mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: remove unused tmpdir
This commit is contained in:
1 parent
18d59edc82
commit
b292c6cfa3
9 files changed
+8
-42
No files matched your search
@@ -27,7 +27,6 @@ Syncing testdata, please wait...: 正在同步测试数据,请稍候...
|
||||
Temp directory: 临时目录
|
||||
Testdata cache directory: 测试数据缓存目录
|
||||
Testdata configuration incorrect.: 题目配置错误。
|
||||
Tmpfs size: tmpfs 分区大小
|
||||
Too many files.: 文件过多。
|
||||
Too many testcases. Cancelled.: 测试数据过多。评测取消。
|
||||
Total time limit longer than {0}s. Cancelled.: 总时限超过{0}s。评测取消。
|
||||
|
||||
@@ -8,11 +8,6 @@ tmp_dir:
|
||||
name: tmp_dir
|
||||
desc: Temp directory
|
||||
default: $TEMP/hydro/judge
|
||||
tmpfs_size:
|
||||
type: text
|
||||
name: tmpfs_size
|
||||
desc: Tmpfs size
|
||||
default: 256m
|
||||
stdio_size:
|
||||
type: text
|
||||
name: stdio_size
|
||||
|
||||
@@ -10,7 +10,6 @@ const argv = cac().parse();
|
||||
const JudgeSettings = Schema.object({
|
||||
cache_dir: Schema.string().default(path.resolve(os.homedir(), '.cache', 'hydro', 'judge')),
|
||||
tmp_dir: Schema.string().default(path.resolve(os.tmpdir(), 'hydro', 'judge')),
|
||||
tmpfs_size: Schema.string().pattern(/^\d+[kmg]b?$/g).default('256m'),
|
||||
stdio_size: Schema.string().pattern(/^\d+[kmg]b?$/g).default('32m'),
|
||||
memoryMax: Schema.string().pattern(/^\d+[kmg]b?$/g).default('512m'),
|
||||
strict_memory: Schema.boolean().default(false),
|
||||
|
||||
@@ -35,7 +35,7 @@ let exit = false;
|
||||
const terminate = async () => {
|
||||
log.info('正在保存数据');
|
||||
try {
|
||||
await Promise.all(global.onDestroy.map((f: Function) => f()));
|
||||
await Promise.all(global.hosts.map((f) => f.dispose?.()));
|
||||
process.exit(1);
|
||||
} catch (e) {
|
||||
if (exit) process.exit(1);
|
||||
|
||||
@@ -173,7 +173,6 @@ export default class Hydro {
|
||||
Authorization: `Bearer ${this.config.cookie.split('sid=')[1].split(';')[0]}`,
|
||||
},
|
||||
});
|
||||
global.onDestroy.push(() => this.ws.close());
|
||||
const content = this.config.minPriority !== undefined
|
||||
? `{"key":"prio","prio":${this.config.minPriority}}`
|
||||
: '{"key":"ping"}';
|
||||
@@ -207,6 +206,10 @@ export default class Hydro {
|
||||
log.info(`[${this.config.host}] 已连接`);
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.ws?.close?.();
|
||||
}
|
||||
|
||||
async setCookie(cookie: string) {
|
||||
this.config.cookie = cookie;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable no-sequences */
|
||||
import { basename } from 'path';
|
||||
import { unlinkSync } from 'fs';
|
||||
import { STATUS } from '@hydrooj/utils/lib/status';
|
||||
import checkers from '../checkers';
|
||||
import compile, { compileChecker, compileValidator } from '../compile';
|
||||
@@ -25,6 +26,7 @@ export async function judge(ctx: Context) {
|
||||
compileValidator(session.getLang, config.validator, judgeExtraFiles).then(markCleanup),
|
||||
ctx.session.fetchFile(ctx.files.hack),
|
||||
]);
|
||||
ctx.clean.push(async () => unlinkSync(input));
|
||||
ctx.next({ status: STATUS.STATUS_JUDGING, progress: 0 });
|
||||
const validateResult = await run(
|
||||
validator.execute,
|
||||
|
||||
@@ -4,7 +4,6 @@ declare module 'hydrooj' {
|
||||
interface SystemKeys {
|
||||
'hydrojudge.cache_dir': string;
|
||||
'hydrojudge.tmp_dir': string;
|
||||
'hydrojudge.tmpfs_size': string;
|
||||
'hydrojudge.sandbox_host': string;
|
||||
'hydrojudge.memoryMax': string;
|
||||
'hydrojudge.testcases_max': number;
|
||||
|
||||
@@ -12,8 +12,7 @@ import { NextFunction, ParsedConfig } from './interface';
|
||||
import judge from './judge';
|
||||
import { Logger } from './log';
|
||||
import { CopyInFile } from './sandbox';
|
||||
import * as tmpfs from './tmpfs';
|
||||
import { compilerText, Lock, md5 } from './utils';
|
||||
import { compilerText, md5 } from './utils';
|
||||
|
||||
interface Session {
|
||||
getLang: (name: string) => LangConfig;
|
||||
@@ -32,7 +31,6 @@ export class JudgeTask {
|
||||
rid: string;
|
||||
lang: string;
|
||||
code: CopyInFile;
|
||||
tmpdir: string;
|
||||
input?: string;
|
||||
clean: (() => Promise<any>)[];
|
||||
data: FileInfo[];
|
||||
@@ -73,11 +71,7 @@ export class JudgeTask {
|
||||
};
|
||||
this.next = this.session.getNext(this);
|
||||
this.end = this.session.getEnd(this);
|
||||
this.tmpdir = path.resolve(getConfig('tmp_dir'), this.rid);
|
||||
this.clean = [];
|
||||
await Lock.acquire(`${host}/${this.source}/${this.rid}`);
|
||||
fs.ensureDirSync(this.tmpdir);
|
||||
tmpfs.mount(this.tmpdir, getConfig('tmpfs_size'));
|
||||
logger.info('Submission: %s/%s/%s', host, this.source, this.rid);
|
||||
await this.doSubmission();
|
||||
} catch (e) {
|
||||
@@ -100,11 +94,8 @@ export class JudgeTask {
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
Lock.release(`${host}/${this.source}/${this.rid}`);
|
||||
// eslint-disable-next-line no-await-in-loop
|
||||
for (const clean of this.clean) await clean()?.catch(() => null);
|
||||
tmpfs.umount(this.tmpdir);
|
||||
fs.removeSync(this.tmpdir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import assert from 'assert';
|
||||
import child from 'child_process';
|
||||
import os from 'os';
|
||||
import fs from 'fs-extra';
|
||||
import log from './log';
|
||||
|
||||
const linux = os.platform() === 'linux';
|
||||
if (!linux) log.warn('Not running on linux. tmpfs disabled.');
|
||||
|
||||
const userInfo = os.userInfo();
|
||||
const uid = userInfo.uid;
|
||||
if (uid !== 0) log.warn('Not running by root. tmpfs disabled.');
|
||||
|
||||
export function mount(path: string, size = '32m') {
|
||||
fs.ensureDirSync(path);
|
||||
assert(size.match(/^\d+[kmg]b?$/gi));
|
||||
if (linux && uid === 0) child.execSync(`mount tmpfs ${path} -t tmpfs -o size=${size}`);
|
||||
}
|
||||
|
||||
export function umount(path: string) {
|
||||
if (linux && uid === 0) child.execSync(`umount ${path}`);
|
||||
}
|
||||
Reference in new issue
Block a user