Skip to content

Commit a08ae56

Browse files
authored
fix: installations being 'broken' if download is interrupted (#201)
Fixes #174
1 parent ec061f7 commit a08ae56

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

.vscode/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
"when": "$(basename).ts"
1111
}
1212
},
13+
"githubIssues.queries":[
14+
{
15+
"label": "Recent Issues",
16+
"query": "state:open repo:${owner}/${repository} sort:updated-desc"
17+
}
18+
],
1319
"prettier.semi": true
14-
}
20+
}

lib/download.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,17 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
302302

303303
for (let i = 0; ; i++) {
304304
try {
305+
// Use a staging directory and rename after unzipping so partially-
306+
// downloaded/unzipped files aren't "stuck" being used.
307+
const downloadStaging = `${downloadedPath}.tmp`;
308+
await fs.promises.rm(downloadStaging, { recursive: true, force: true });
309+
305310
const { stream, format } = await downloadVSCodeArchive({ version, platform, cachePath, reporter, timeout });
306-
await unzipVSCode(reporter, downloadedPath, extractSync, stream, format);
311+
// important! do not put anything async here, since unzipVSCode will need
312+
// to start consuming the stream immediately.
313+
await unzipVSCode(reporter, downloadStaging, extractSync, stream, format);
314+
await fs.promises.rename(downloadStaging, downloadedPath);
315+
307316
reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath });
308317
break;
309318
} catch (error) {

0 commit comments

Comments
 (0)