judge: optional copyOut (#153)

* NOTICE: please upgrade sandbox to at lease v1.2.0
This commit is contained in:
undefined committed 2021-06-06 11:54:48 +08:00
1 parent 5e0eb372f6
commit b1f1ceb4c9
4 files changed
+12 -3

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "@hydrooj/hydrojudge", "name": "@hydrooj/hydrojudge",
"bin": "bin/hydrojudge.js", "bin": "bin/hydrojudge.js",
"version": "2.8.1", "version": "2.8.2",
"main": "package.json", "main": "package.json",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"repository": "https://github.com/hydro-dev/Hydro.git", "repository": "https://github.com/hydro-dev/Hydro.git",
+1 -1
View File
@@ -37,7 +37,7 @@ function judgeCase(c, sid) {
const { filename } = ctx.config; const { filename } = ctx.config;
const copyIn = { ...ctx.execute.copyIn }; const copyIn = { ...ctx.execute.copyIn };
if (filename) copyIn[`${filename}.in`] = c.input ? { src: c.input } : { content: '' }; 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 stdin = filename ? null : c.input;
const stdout = path.resolve(ctx.tmpdir, `${c.id}.out`); const stdout = path.resolve(ctx.tmpdir, `${c.id}.out`);
const stderr = path.resolve(ctx.tmpdir, `${c.id}.err`); const stderr = path.resolve(ctx.tmpdir, `${c.id}.err`);
+1 -1
View File
@@ -55,7 +55,7 @@ export const judge = async (ctx) => {
const copyIn = { ...ctx.execute.copyIn }; const copyIn = { ...ctx.execute.copyIn };
const { filename } = ctx.config; const { filename } = ctx.config;
if (filename) copyIn[`${filename}.in`] = { content: ctx.input }; 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'); const stdin = path.resolve(ctx.tmpdir, '0.in');
await fs.writeFile(stdin, ctx.input || ''); await fs.writeFile(stdin, ctx.input || '');
const stdout = path.resolve(ctx.tmpdir, '0.out'); const stdout = path.resolve(ctx.tmpdir, '0.out');
+9
View File
@@ -10,6 +10,7 @@ import { Logger } from './log';
const argv = cac().parse(); const argv = cac().parse();
const logger = new Logger('sandbox'); const logger = new Logger('sandbox');
let callId = 0; let callId = 0;
let supportOptional = false;
const statusMap = { const statusMap = {
'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED, 'Time Limit Exceeded': STATUS.STATUS_TIME_LIMIT_EXCEEDED,
@@ -29,6 +30,9 @@ function proc({
process_limit = 32, process_limit = 32,
stdin = '', copyIn = {}, copyOut = [], copyOutCached = [], 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')); const size = parseMemoryMB(getConfig('stdio_size'));
return { return {
args: cmd(execute.replace(/\$\{dir\}/g, '/w')), args: cmd(execute.replace(/\$\{dir\}/g, '/w')),
@@ -112,6 +116,11 @@ export async function run(execute, params?) {
// eslint-disable-next-line no-return-await // eslint-disable-next-line no-return-await
if (typeof execute === 'object') return await runMultiple(execute); if (typeof execute === 'object') return await runMultiple(execute);
try { 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 body = { cmd: [proc({ execute, ...params })] };
const id = callId++; const id = callId++;
if (argv.options['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body)); if (argv.options['show-sandbox-call']) logger.debug('%d %s', id, JSON.stringify(body));