mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
judge: ignore tmpfs error
This commit is contained in:
1 parent
b8c316c44b
commit
4b7f18baaa
3 files changed
+35
-28
No files matched your search
@@ -1,11 +1,8 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/hydrojudge",
|
"name": "@hydrooj/hydrojudge",
|
||||||
"version": "2.0.13",
|
"version": "2.0.14",
|
||||||
"main": "package.json",
|
"main": "package.json",
|
||||||
"author": "masnn",
|
"author": "masnn",
|
||||||
"os": [
|
|
||||||
"linux"
|
|
||||||
],
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.20.0",
|
"axios": "^0.20.0",
|
||||||
"bson": "^4.1.0",
|
"bson": "^4.1.0",
|
||||||
|
|||||||
@@ -20,9 +20,10 @@ const cache: any = {};
|
|||||||
|
|
||||||
async function stackSize() {
|
async function stackSize() {
|
||||||
let output = '';
|
let output = '';
|
||||||
const context: any = {
|
try {
|
||||||
lang: 'ccWithoutO2',
|
const context: any = {
|
||||||
code: `#include <iostream>
|
lang: 'ccWithoutO2',
|
||||||
|
code: `#include <iostream>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
int i=1;
|
int i=1;
|
||||||
int main(){
|
int main(){
|
||||||
@@ -32,25 +33,28 @@ int main(){
|
|||||||
if (i>256) return 0;
|
if (i>256) return 0;
|
||||||
main();
|
main();
|
||||||
}`,
|
}`,
|
||||||
config: {
|
config: {
|
||||||
time: 3000,
|
time: 3000,
|
||||||
memory: 256,
|
memory: 256,
|
||||||
},
|
},
|
||||||
stat: {},
|
stat: {},
|
||||||
clean: [],
|
clean: [],
|
||||||
next: (data) => {
|
next: (data) => {
|
||||||
if (data.case) output = data.case.message;
|
if (data.case) output = data.case.message;
|
||||||
},
|
},
|
||||||
end: () => { },
|
end: () => { },
|
||||||
};
|
};
|
||||||
context.tmpdir = path.resolve(tmpdir(), 'hydro', 'tmp', 'sysinfo');
|
context.tmpdir = path.resolve(tmpdir(), 'hydro', 'tmp', 'sysinfo');
|
||||||
fs.ensureDirSync(context.tmpdir);
|
fs.ensureDirSync(context.tmpdir);
|
||||||
tmpfs.mount(context.tmpdir, '64m');
|
tmpfs.mount(context.tmpdir, '64m');
|
||||||
await judge(context).catch((e) => console.error(e));
|
await judge(context).catch((e) => console.error(e));
|
||||||
// eslint-disable-next-line no-await-in-loop
|
// eslint-disable-next-line no-await-in-loop
|
||||||
for (const clean of context.clean) await clean().catch();
|
for (const clean of context.clean) await clean().catch();
|
||||||
tmpfs.umount(context.tmpdir);
|
tmpfs.umount(context.tmpdir);
|
||||||
fs.removeSync(context.tmpdir);
|
fs.removeSync(context.tmpdir);
|
||||||
|
} catch (e) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
const a = output.split(' ');
|
const a = output.split(' ');
|
||||||
return parseInt(a[a.length - 2], 10);
|
return parseInt(a[a.length - 2], 10);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
import child from 'child_process';
|
import child from 'child_process';
|
||||||
import fs from 'fs-extra';
|
import fs from 'fs-extra';
|
||||||
|
import os from 'os';
|
||||||
|
import { Logger } from 'hydrooj/dist/logger';
|
||||||
|
|
||||||
|
const logger = new Logger('judge');
|
||||||
|
const linux = os.platform() === 'linux';
|
||||||
|
if (!linux) logger.warn('Not running on linux. tmpfs disabled.');
|
||||||
|
|
||||||
export function mount(path: string, size = '32m') {
|
export function mount(path: string, size = '32m') {
|
||||||
fs.ensureDirSync(path);
|
fs.ensureDirSync(path);
|
||||||
child.execSync(`mount tmpfs ${path} -t tmpfs -o size=${size}`);
|
if (linux) child.execSync(`mount tmpfs ${path} -t tmpfs -o size=${size}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function umount(path: string) {
|
export function umount(path: string) {
|
||||||
child.execSync(`umount ${path}`);
|
if (linux) child.execSync(`umount ${path}`);
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user