Skip to content

Commit a0a7cd3

Browse files
committed
Use retry dialog also for downloads
Since the change already implements a retry dialog for network operations, let's also use it for allowing to retry the actual file.
1 parent 1503d9d commit a0a7cd3

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

editors/code/src/main.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,19 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
194194
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
195195

196196
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
197-
await download({
198-
url: artifact.browser_download_url,
199-
dest,
200-
progressTitle: "Downloading rust-analyzer extension",
201-
});
197+
198+
await performDownloadWithRetryDialog(async () => {
199+
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
200+
await fs.unlink(dest).catch(err => {
201+
if (err.code !== "ENOENT") throw err;
202+
});
203+
204+
await download({
205+
url: artifact.browser_download_url,
206+
dest,
207+
progressTitle: "Downloading rust-analyzer extension",
208+
});
209+
}, state);
202210

203211
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
204212
await fs.unlink(dest);
@@ -317,18 +325,20 @@ async function getServer(config: Config, state: PersistentState): Promise<string
317325
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
318326
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
319327

320-
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
321-
await fs.unlink(dest).catch(err => {
322-
if (err.code !== "ENOENT") throw err;
323-
});
324-
325-
await download({
326-
url: artifact.browser_download_url,
327-
dest,
328-
progressTitle: "Downloading rust-analyzer server",
329-
gunzip: true,
330-
mode: 0o755
331-
});
328+
await performDownloadWithRetryDialog(async () => {
329+
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
330+
await fs.unlink(dest).catch(err => {
331+
if (err.code !== "ENOENT") throw err;
332+
});
333+
334+
await download({
335+
url: artifact.browser_download_url,
336+
dest,
337+
progressTitle: "Downloading rust-analyzer server",
338+
gunzip: true,
339+
mode: 0o755
340+
});
341+
}, state);
332342

333343
// Patching executable if that's NixOS.
334344
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
@@ -372,15 +382,15 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
372382
password: true,
373383
prompt: `
374384
This dialog allows to store a Github authorization token.
375-
The usage of an authorization token allows will increase the rate
385+
The usage of an authorization token will increase the rate
376386
limit on the use of Github APIs and can thereby prevent getting
377387
throttled.
378-
Auth tokens can be obtained at https://github.com/settings/tokens`,
388+
Auth tokens can be created at https://github.com/settings/tokens`,
379389
};
380390

381391
const newToken = await vscode.window.showInputBox(githubTokenOptions);
382392
if (newToken) {
383393
log.info("Storing new github token");
384394
await state.updateGithubToken(newToken);
385395
}
386-
}
396+
}

0 commit comments

Comments
 (0)