mirror of
https://github.com/Trollobot/Telemax.git
synced 2026-10-19 10:23:24 +00:00
1.3.0-beta.7: уборка хранилища не удаляет файл, который ещё сохраняется из MAX (образ 2,7 ГБ удалялся посреди скачивания)
This commit is contained in:
parent
9bdf4340dc
commit
ddfa16f527
4 changed files with 27 additions and 6 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "telemax",
|
||||
"version": "1.3.0-beta.6",
|
||||
"version": "1.3.0-beta.7",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "telemax",
|
||||
"version": "1.3.0-beta.6",
|
||||
"version": "1.3.0-beta.7",
|
||||
"license": "AGPL-3.0-only",
|
||||
"dependencies": {
|
||||
"dotenv": "^17.2.3",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "telemax",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-only",
|
||||
"version": "1.3.0-beta.6",
|
||||
"version": "1.3.0-beta.7",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/server/app.ts",
|
||||
|
|
|
|||
|
|
@ -289,12 +289,15 @@ export class FileShare {
|
|||
const id = newToken();
|
||||
const safe = safeFileName(name);
|
||||
const dir = path.join(this.dir, 'items', id);
|
||||
// Registered BEFORE the directory exists: sweep() deletes item directories the index doesn't
|
||||
// know, and a file being saved isn't in the index yet (a 2.7 GB ISO was deleted mid-download
|
||||
// that way, live 2026-10-09).
|
||||
const progress = { name: safe, size, written: 0 };
|
||||
this.saving.set(id, progress);
|
||||
await mkdir(dir, { recursive: true });
|
||||
const part = path.join(dir, `${safe}.part`);
|
||||
let written = 0;
|
||||
const limit = Math.max(size, 0) + 1024 * 1024; // the declared size, a little slack
|
||||
const progress = { name: safe, size, written: 0 };
|
||||
this.saving.set(id, progress);
|
||||
const guard = new Transform({
|
||||
transform(chunk: Buffer, _enc, cb) {
|
||||
written += chunk.length;
|
||||
|
|
@ -420,7 +423,7 @@ export class FileShare {
|
|||
if (!liveTokens.has(name.replace(/\.json(\.tmp)?$/, ''))) await unlink(path.join(this.dir, 'tokens', name)).catch(() => {});
|
||||
}
|
||||
for (const name of await readdir(path.join(this.dir, 'items')).catch(() => [] as string[])) {
|
||||
if (!liveItems.has(name)) await rm(path.join(this.dir, 'items', name), { recursive: true, force: true });
|
||||
if (!liveItems.has(name) && !this.saving.has(name)) await rm(path.join(this.dir, 'items', name), { recursive: true, force: true });
|
||||
}
|
||||
for (const name of await readdir(path.join(this.dir, 'incoming')).catch(() => [] as string[])) {
|
||||
if (!liveTokens.has(name)) await rm(path.join(this.dir, 'incoming', name), { recursive: true, force: true });
|
||||
|
|
|
|||
|
|
@ -169,3 +169,21 @@ describe('FileShare.ensureService', () => {
|
|||
expect((await (await fresh({ ...opts, enabled: false })).ensureService(10)).ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('FileShare sweep vs a file being saved', () => {
|
||||
it('leaves a file that is still being written alone (live 2026-10-09: a 2.7 GB ISO was deleted mid-download)', async () => {
|
||||
const share = new FileShare(dataDir, opts);
|
||||
await share.init();
|
||||
const body = new Readable({ read() {} });
|
||||
const saving = share.storeStream(body, 'big.iso', 6);
|
||||
body.push(Buffer.from('abc'));
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
expect(share.inProgress()).toEqual([{ name: 'big.iso', size: 6, written: 3 }]);
|
||||
await share.sweep();
|
||||
body.push(Buffer.from('def'));
|
||||
body.push(null);
|
||||
const f = await saving;
|
||||
expect(await readFile(path.join(share.dir, 'items', f.id, 'big.iso'), 'utf8')).toBe('abcdef');
|
||||
expect(share.inProgress()).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue