|
|
|
@ -319,11 +319,13 @@ class Problem extends Model {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async updateTestdata(path, noLimit) { |
|
|
|
|
let AdmZip = require('adm-zip'); |
|
|
|
|
let zip = new AdmZip(path); |
|
|
|
|
await syzoj.utils.lock(['Problem::Testdata', this.id], async () => { |
|
|
|
|
let p7zip = new (require('node-7z')); |
|
|
|
|
|
|
|
|
|
let unzipSize = 0; |
|
|
|
|
for (let x of zip.getEntries()) unzipSize += x.header.size; |
|
|
|
|
await p7zip.list(path).progress(files => { |
|
|
|
|
for (let file of files) unzipSize += file.size; |
|
|
|
|
}); |
|
|
|
|
if (!noLimit && unzipSize > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
|
|
|
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
@ -331,11 +333,13 @@ class Problem extends Model {
|
|
|
|
|
await fs.removeAsync(dir); |
|
|
|
|
await fs.ensureDirAsync(dir); |
|
|
|
|
|
|
|
|
|
zip.extractAllTo(dir); |
|
|
|
|
await p7zip.extract(path, dir); |
|
|
|
|
await fs.moveAsync(path, dir + '.zip', { overwrite: true }); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async uploadTestdataSingleFile(filename, filepath, size, noLimit) { |
|
|
|
|
await syzoj.utils.lock(['Promise::Testdata', this.id], async () => { |
|
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
|
let fs = Promise.promisifyAll(require('fs-extra')), path = require('path'); |
|
|
|
|
await fs.ensureDirAsync(dir); |
|
|
|
@ -350,25 +354,28 @@ class Problem extends Model {
|
|
|
|
|
|
|
|
|
|
await fs.moveAsync(filepath, path.join(dir, filename), { overwrite: true }); |
|
|
|
|
await fs.removeAsync(dir + '.zip'); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async deleteTestdataSingleFile(filename) { |
|
|
|
|
await syzoj.utils.lock(['Promise::Testdata', this.id], async () => { |
|
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
|
let fs = Promise.promisifyAll(require('fs-extra')), path = require('path'); |
|
|
|
|
await fs.removeAsync(path.join(dir, filename)); |
|
|
|
|
await fs.removeAsync(dir + '.zip'); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async makeTestdataZip() { |
|
|
|
|
await syzoj.utils.lock(['Promise::Testdata', this.id], async () => { |
|
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
|
if (!await syzoj.utils.isDir(dir)) throw new ErrorMessage('无测试数据。'); |
|
|
|
|
|
|
|
|
|
let AdmZip = require('adm-zip'); |
|
|
|
|
let zip = new AdmZip(); |
|
|
|
|
let p7zip = new (require('node-7z')); |
|
|
|
|
|
|
|
|
|
let list = await this.listTestdata(); |
|
|
|
|
for (let file of list.files) zip.addLocalFile(require('path').join(dir, file.filename), '', file.filename); |
|
|
|
|
zip.writeZip(dir + '.zip'); |
|
|
|
|
let list = await this.listTestdata(), path = require('path'); |
|
|
|
|
await p7zip.add(dir + '.zip', list.files.map(file => path.join(dir, file.filename))); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async hasSpecialJudge() { |
|
|
|
|