mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-06 02:25:24 +00:00
fix: remove the partial file when a desktop download is aborted early
This commit is contained in:
1 parent
c7aa1c64b5
commit
ea4e2d2124
2 files changed
+21
No files matched your search
@@ -560,7 +560,13 @@ export async function openDownload(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
abort: async () => {
|
abort: async () => {
|
||||||
|
// The file opens in the background, so wait for the stream to close
|
||||||
|
// or a late open would leave the partial file behind.
|
||||||
|
await new Promise<void>((resolve) => {
|
||||||
|
if (stream.closed) return resolve();
|
||||||
|
stream.once("close", () => resolve());
|
||||||
stream.destroy();
|
stream.destroy();
|
||||||
|
});
|
||||||
await fsp.rm(partialPath, { force: true }).catch(() => {});
|
await fsp.rm(partialPath, { force: true }).catch(() => {});
|
||||||
release();
|
release();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -186,6 +186,21 @@ describe("ctx.desktop.local", () => {
|
|||||||
expect(fs.readdirSync(dir)).toEqual([]);
|
expect(fs.readdirSync(dir)).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("leaves no partial file when aborted before the file has opened", async () => {
|
||||||
|
grants.set("demo", ["desktop:local"]);
|
||||||
|
const ctx = contextFor("demo", ["desktop:local"]);
|
||||||
|
for (let i = 0; i < 20; i++) {
|
||||||
|
const download = await ctx.desktop.local.fs.openDownload({
|
||||||
|
rootPath: dir,
|
||||||
|
destPath: path.join(dir, `early-${i}.txt`),
|
||||||
|
transferId: `early-${i}`,
|
||||||
|
});
|
||||||
|
await download.abort();
|
||||||
|
}
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||||
|
expect(fs.readdirSync(dir)).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
it("sends trash and open through Electron main and audits each call", async () => {
|
it("sends trash and open through Electron main and audits each call", async () => {
|
||||||
grants.set("demo", ["desktop:local"]);
|
grants.set("demo", ["desktop:local"]);
|
||||||
const ctx = contextFor("demo", ["desktop:local"]);
|
const ctx = contextFor("demo", ["desktop:local"]);
|
||||||
|
|||||||
Reference in new issue
Block a user