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