mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-11-05 18:15: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
+22
-1
No files matched your search
@@ -560,7 +560,13 @@ export async function openDownload(
|
||||
}
|
||||
},
|
||||
abort: async () => {
|
||||
stream.destroy();
|
||||
// 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();
|
||||
});
|
||||
await fsp.rm(partialPath, { force: true }).catch(() => {});
|
||||
release();
|
||||
},
|
||||
|
||||
@@ -186,6 +186,21 @@ describe("ctx.desktop.local", () => {
|
||||
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 () => {
|
||||
grants.set("demo", ["desktop:local"]);
|
||||
const ctx = contextFor("demo", ["desktop:local"]);
|
||||
|
||||
Reference in new issue
Block a user