|
|
@ -322,10 +322,12 @@ class Problem extends Model { |
|
|
|
await syzoj.utils.lock(['Problem::Testdata', this.id], async () => { |
|
|
|
await syzoj.utils.lock(['Problem::Testdata', this.id], async () => { |
|
|
|
let p7zip = new (require('node-7z')); |
|
|
|
let p7zip = new (require('node-7z')); |
|
|
|
|
|
|
|
|
|
|
|
let unzipSize = 0; |
|
|
|
let unzipSize = 0, unzipCount; |
|
|
|
await p7zip.list(path).progress(files => { |
|
|
|
await p7zip.list(path).progress(files => { |
|
|
|
|
|
|
|
unzipCount = files.length; |
|
|
|
for (let file of files) unzipSize += file.size; |
|
|
|
for (let file of files) unzipSize += file.size; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
if (!noLimit && unzipCount > syzoj.config.limit.testdata_filecount) throw new ErrorMessage('数据包中的文件太多。'); |
|
|
|
if (!noLimit && unzipSize > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
if (!noLimit && unzipSize > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
|
|
|
|
|
|
|
|
let dir = this.getTestdataPath(); |
|
|
|
let dir = this.getTestdataPath(); |
|
|
@ -344,13 +346,17 @@ class Problem extends Model { |
|
|
|
let fs = Promise.promisifyAll(require('fs-extra')), path = require('path'); |
|
|
|
let fs = Promise.promisifyAll(require('fs-extra')), path = require('path'); |
|
|
|
await fs.ensureDirAsync(dir); |
|
|
|
await fs.ensureDirAsync(dir); |
|
|
|
|
|
|
|
|
|
|
|
let oldSize = 0; |
|
|
|
let oldSize = 0, list = await this.listTestdata(), replace = false, oldCount = 0; |
|
|
|
let list = await this.listTestdata(); |
|
|
|
|
|
|
|
if (list) { |
|
|
|
if (list) { |
|
|
|
for (let file of list.files) if (file.filename !== filename) oldSize += file.size; |
|
|
|
oldCount = list.files.length; |
|
|
|
|
|
|
|
for (let file of list.files) { |
|
|
|
|
|
|
|
if (file.filename !== filename) oldSize += file.size; |
|
|
|
|
|
|
|
else replace = true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!noLimit && oldSize + size > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
if (!noLimit && oldSize + size > syzoj.config.limit.testdata) throw new ErrorMessage('数据包太大。'); |
|
|
|
|
|
|
|
if (!noLimit && oldCount + !replace > syzoj.config.limit.testdata_filecount) 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'); |
|
|
|