Skip to content

Commit

Permalink
Merge pull request #237 from microsoft/connor4312/issue-233
Browse files Browse the repository at this point in the history
fix: windows sometimes failing on EPERM in download
  • Loading branch information
connor4312 authored Oct 4, 2023
2 parents 453dba5 + 6230871 commit 0be636f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 2.3.5 | 2022-10-04

- Fix windows sometimes failing on EPERM in download

### 2.3.4 | 2022-07-31

- Fix "insiders" string not matching correctly
Expand Down
16 changes: 15 additions & 1 deletion lib/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
streamToBuffer,
systemDefaultPlatform,
} from './util';
import * as timers from 'timers/promises';

const extensionRoot = process.cwd();
const pipelineAsync = promisify(pipeline);
Expand Down Expand Up @@ -422,7 +423,20 @@ export async function download(options: Partial<DownloadOptions> = {}): Promise<
// important! do not put anything async here, since unzipVSCode will need
// to start consuming the stream immediately.
await unzipVSCode(reporter, downloadStaging, stream, platform, format);
await fs.promises.rename(downloadStaging, downloadedPath);

// Windows file handles can get released asynchronously, give it a few retries:
for (let attempts = 20; attempts >= 0; attempts--) {
try {
await fs.promises.rename(downloadStaging, downloadedPath);
break;
} catch (e) {
if (attempts === 0) {
throw e;
} else {
await timers.setTimeout(200);
}
}
}

reporter.report({ stage: ProgressReportStage.NewInstallComplete, downloadedPath });
break;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vscode/test-electron",
"version": "2.3.4",
"version": "2.3.5",
"scripts": {
"compile": "tsc -p ./",
"watch": "tsc -w -p ./",
Expand Down

0 comments on commit 0be636f

Please sign in to comment.