mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
judge: optional copyOut (#153)
* NOTICE: please upgrade sandbox to at lease v1.2.0
This commit is contained in:
1 parent
5e0eb372f6
commit
b1f1ceb4c9
4 files changed
+12
-3
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"bin": "bin/hydrojudge.js",
|
||||
"version": "2.8.1",
|
||||
"version": "2.8.2",
|
||||
"main": "package.json",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -37,7 +37,7 @@ function judgeCase(c, sid) {
|
||||
const { filename } = ctx.config;
|
||||
const copyIn = { ...ctx.execute.copyIn };
|
||||
if (filename) copyIn[`${filename}.in`] = c.input ? { src: c.input } : { content: '' };
|
||||
const copyOut = filename ? [`${filename}.out`] : [];
|
||||
const copyOut = filename ? [`${filename}.out?`] : [];
|
||||
const stdin = filename ? null : c.input;
|
||||
const stdout = path.resolve(ctx.tmpdir, `${c.id}.out`);
|
||||
const stderr = path.resolve(ctx.tmpdir, `${c.id}.err`);
|
||||
|
||||
@@ -55,7 +55,7 @@ export const judge = async (ctx) => {
|
||||
const copyIn = { ...ctx.execute.copyIn };
|
||||
const { filename } = ctx.config;
|
||||
if (filename) copyIn[`${filename}.in`] = { content: ctx.input };
|
||||
const copyOut = filename ? [`${filename}.out`] : [];
|
||||
const copyOut = filename ? [`${filename}.out?`] : [];
|
||||
const stdin = path.resolve(ctx.tmpdir, '0.in');
|
||||
await fs.writeFile(stdin, ctx.input || '');
|
||||
const stdout = path.resolve(ctx.tmpdir, '0.out');
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Logger } from './log';
|
||||
const argv = cac().parse();
|
||||
const logger = new Logger('sandbox');
|
||||
let callId = 0;
|
||||
let supportOptional = false;
|
||||
|
||||
const statusMap = {
|
||||
'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED,
|
||||
@@ -29,6 +30,9 @@ function proc({
|
||||
process_limit = 32,
|
||||
stdin = '', copyIn = {}, copyOut = [], copyOutCached = [],
|
||||
} = {}) {
|
||||
if (!supportOptional) {
|
||||
copyOut = (copyOut as string[]).map((i) => (i.endsWith('?') ? i.substr(0, i.length - 1) : i));
|
||||
}
|
||||
const size = parseMemoryMB(getConfig('stdio_size'));
|
||||
return {
|
||||
args: cmd(execute.replace(/\$\{dir\}/g, '/w')),
|
||||
@@ -112,6 +116,11 @@ export async function run(execute, params?) {
|
||||
// eslint-disable-next-line no-return-await
|
||||
if (typeof execute === 'object') return await runMultiple(execute);
|
||||
try {
|
||||
if (!supportOptional) {
|
||||
const res = await Axios.create({ baseURL: getConfig('sandbox_host') }).get('/version');
|
||||
supportOptional = res.data.copyOutOptional;
|
||||
if (!supportOptional) logger.warn('Sandbox version tooooooo low! Please upgrade to at least 1.2.0');
|
||||
}
|
||||
const body = { cmd: [proc({ execute, ...params })] };
|
||||
const id = callId++;
|
||||
if (argv.options['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));
|
||||
|
||||
Reference in new issue
Block a user