Skip to content

Commit 51a9ec1

Browse files
committed
fix: delete existing file before download to prevent corruption
CI caching can restore partial/corrupted downloads that cause extraction failures. Delete any existing file before starting the download to ensure a clean state.
1 parent e107dfa commit 51a9ec1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/http-request.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
* - Zero dependencies on external HTTP libraries.
1515
*/
1616

17+
import { safeDelete } from './fs.js'
18+
1719
let _fs: typeof import('node:fs') | undefined
1820

1921
/**
@@ -918,6 +920,13 @@ export async function httpDownload(
918920
}
919921
}
920922

923+
// Delete existing file before download to prevent partial/corrupted file issues.
924+
// CI caching can restore partial downloads that cause extraction failures.
925+
const fs = getFs()
926+
if (fs.existsSync(destPath)) {
927+
await safeDelete(destPath)
928+
}
929+
921930
// Retry logic with exponential backoff
922931
let lastError: Error | undefined
923932
for (let attempt = 0; attempt <= retries; attempt++) {

src/releases/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ export async function downloadReleaseAsset(
313313
await safeMkdir(path.dirname(outputPath))
314314

315315
// Download using httpDownload which supports redirects and retries.
316+
// httpDownload deletes existing files before downloading to prevent partial/corrupted issues.
316317
await httpDownload(downloadUrl, outputPath, {
317318
logger: quiet ? undefined : logger,
318319
progressInterval: 10,

0 commit comments

Comments
 (0)