mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
judge: auto-remove extra files (#104)
This commit is contained in:
1 parent
c977a51de9
commit
a7fd32cac9
6 files changed
+26
-2
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@hydrooj/hydrojudge",
|
||||
"bin": "bin/hydrojudge.js",
|
||||
"version": "2.5.8",
|
||||
"version": "2.5.9",
|
||||
"main": "package.json",
|
||||
"author": "undefined <i@undefined.moe>",
|
||||
"repository": "https://github.com/hydro-dev/Hydro.git",
|
||||
|
||||
@@ -202,10 +202,15 @@ export default class Hydro {
|
||||
} catch (e) { /* ignore */ }
|
||||
const version = {};
|
||||
const filenames = [];
|
||||
const allFiles = new Set<string>();
|
||||
for (const file of files) {
|
||||
allFiles.add(file.name);
|
||||
version[file.name] = file.etag;
|
||||
if (etags[file.name] !== file.etag) filenames.push(file.name);
|
||||
}
|
||||
for (const name in etags) {
|
||||
if (!allFiles.has(name)) await fs.rm(path.join(filePath, name));
|
||||
}
|
||||
if (filenames.length) {
|
||||
log.info(`Getting problem data: ${this.config.host}/${domainId}/${pid}`);
|
||||
if (next) next({ judge_text: '正在同步测试数据,请稍后' });
|
||||
|
||||
@@ -24,6 +24,7 @@ declare module 'hydrooj/dist/interface' {
|
||||
'hydrojudge.tmpfs_size': string,
|
||||
'hydrojudge.retry_delay_sec': number,
|
||||
'hydrojudge.sandbox_host': string,
|
||||
'hydrojudge.memoryMax': string,
|
||||
'hydrojudge.testcases_max': number,
|
||||
'hydrojudge.total_time_limit': number,
|
||||
'hydrojudge.parallelism': number,
|
||||
@@ -81,12 +82,17 @@ async function postInit() {
|
||||
etags = JSON.parse(fs.readFileSync(path.join(filePath, 'etags')).toString());
|
||||
} catch (e) { /* ignore */ }
|
||||
const version = {};
|
||||
const filenames = new Set<string>();
|
||||
for (const file of files) {
|
||||
filenames.add(file.name);
|
||||
version[file.name] = file.etag;
|
||||
if (etags[file.name] !== file.etag) {
|
||||
await storage.get(`problem/${domainId}/${pid}/testdata/${file.name}`, path.join(filePath, file.name));
|
||||
}
|
||||
}
|
||||
for (const name in etags) {
|
||||
if (!filenames.has(name)) await fs.rm(path.join(filePath, name));
|
||||
}
|
||||
fs.writeFileSync(path.join(filePath, 'etags'), JSON.stringify(version));
|
||||
fs.writeFileSync(path.join(filePath, 'lastUsage'), new Date().getTime().toString());
|
||||
await processData(filePath).catch(noop);
|
||||
|
||||
Reference in new issue
Block a user