judge: submit_answer: simplify logic

This commit is contained in:
undefined committed 2022-04-05 23:04:53 +08:00
1 parent 8e9854b1f3
commit c383c40477
2 files changed
+32 -24

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.17.0", "version": "2.17.1",
"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",
+31 -23
View File
@@ -1,3 +1,4 @@
import { readFile } from 'fs-extra';
import Queue from 'p-queue'; import Queue from 'p-queue';
import { STATUS } from '@hydrooj/utils/lib/status'; import { STATUS } from '@hydrooj/utils/lib/status';
import { check, compileChecker } from '../check'; import { check, compileChecker } from '../check';
@@ -33,43 +34,50 @@ function judgeCase(c: Case, sid: string) {
}, c.id); }, c.id);
return; return;
} }
const chars = /[a-zA-Z0-9_.-]/;
const res = await run( const name = await readFile(c.input, 'utf-8').then((res) => res.trim().split('').filter((i) => chars.test(i)).join(''));
ctx.config.subType === 'multi' let file = ctx.code;
? '/bin/bash -c "unzip foo.zip >/dev/null && read line && cat $line"' let status = STATUS.STATUS_ACCEPTED;
: '/bin/cat foo.zip',
{
stdin: c.input,
copyIn: { 'foo.zip': ctx.code },
copyOutCached: [],
time: 1000,
memory: 128,
cacheStdoutAndStderr: true,
},
);
const { code } = res;
let { status } = res;
let message: any = ''; let message: any = '';
let score = 0; let score = 0;
const fileIds = [];
if (ctx.config.subType === 'multi') {
const res = await run(
'/usr/bin/unzip foo.zip',
{
stdin: null,
copyIn: { 'foo.zip': ctx.code },
copyOutCached: [`${name}?`],
time: 1000,
memory: 128,
cacheStdoutAndStderr: true,
},
);
if (res.status === STATUS.STATUS_RUNTIME_ERROR && res.code) {
message = { message: 'Unzip failed.' };
status = STATUS.STATUS_WRONG_ANSWER;
} else if (!res.fileIds[name]) {
message = { message: 'File not found.' };
status = STATUS.STATUS_WRONG_ANSWER;
}
file = { fileId: res.fileIds[name] };
fileIds.push(...Object.values(res.fileIds));
}
if (status === STATUS.STATUS_ACCEPTED) { if (status === STATUS.STATUS_ACCEPTED) {
[status, score, message] = await check({ [status, score, message] = await check({
execute: ctx.checker.execute, execute: ctx.checker.execute,
copyIn: ctx.checker.copyIn || {}, copyIn: ctx.checker.copyIn || {},
input: { src: c.input }, input: { src: c.input },
output: { src: c.output }, output: { src: c.output },
user_stdout: { fileId: res.fileIds['stdout'] }, user_stdout: file,
user_stderr: { fileId: res.fileIds['stderr'] }, user_stderr: { content: '' },
checker_type: ctx.config.checker_type, checker_type: ctx.config.checker_type,
score: ctxSubtask.subtask.score, score: ctxSubtask.subtask.score,
detail: ctx.config.detail ?? true, detail: ctx.config.detail ?? true,
env: { ...ctx.env, HYDRO_TESTCASE: c.id.toString() }, env: { ...ctx.env, HYDRO_TESTCASE: c.id.toString() },
}); });
} else if (status === STATUS.STATUS_RUNTIME_ERROR && code) {
message = { message: 'Unzip failed or file not found.' };
} }
await Promise.all( await Promise.all(fileIds.map(del)).catch(() => { /* Ignore file doesn't exist */ });
Object.values(res.fileIds).map((id) => del(id)),
).catch(() => { /* Ignore file doesn't exist */ });
ctxSubtask.score = Score[ctxSubtask.subtask.type](ctxSubtask.score, score); ctxSubtask.score = Score[ctxSubtask.subtask.type](ctxSubtask.score, score);
ctxSubtask.status = Math.max(ctxSubtask.status, status); ctxSubtask.status = Math.max(ctxSubtask.status, status);
if (ctxSubtask.status > STATUS.STATUS_ACCEPTED) ctx.failed[sid] = true; if (ctxSubtask.status > STATUS.STATUS_ACCEPTED) ctx.failed[sid] = true;