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.
This commit is contained in:
Matthias Einwag 2020-09-23 00:28:38 -07:00
parent 1503d9de41
commit a0a7cd306e

View file

@ -194,11 +194,19 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
await download({
url: artifact.browser_download_url, await performDownloadWithRetryDialog(async () => {
dest, // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
progressTitle: "Downloading rust-analyzer extension", await fs.unlink(dest).catch(err => {
}); if (err.code !== "ENOENT") throw err;
});
await download({
url: artifact.browser_download_url,
dest,
progressTitle: "Downloading rust-analyzer extension",
});
}, state);
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest)); await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
await fs.unlink(dest); await fs.unlink(dest);
@ -317,18 +325,20 @@ async function getServer(config: Config, state: PersistentState): Promise<string
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`); const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. await performDownloadWithRetryDialog(async () => {
await fs.unlink(dest).catch(err => { // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
if (err.code !== "ENOENT") throw err; await fs.unlink(dest).catch(err => {
}); if (err.code !== "ENOENT") throw err;
});
await download({ await download({
url: artifact.browser_download_url, url: artifact.browser_download_url,
dest, dest,
progressTitle: "Downloading rust-analyzer server", progressTitle: "Downloading rust-analyzer server",
gunzip: true, gunzip: true,
mode: 0o755 mode: 0o755
}); });
}, state);
// Patching executable if that's NixOS. // Patching executable if that's NixOS.
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) { if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
@ -372,10 +382,10 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
password: true, password: true,
prompt: ` prompt: `
This dialog allows to store a Github authorization token. This dialog allows to store a Github authorization token.
The usage of an authorization token allows will increase the rate The usage of an authorization token will increase the rate
limit on the use of Github APIs and can thereby prevent getting limit on the use of Github APIs and can thereby prevent getting
throttled. throttled.
Auth tokens can be obtained at https://github.com/settings/tokens`, Auth tokens can be created at https://github.com/settings/tokens`,
}; };
const newToken = await vscode.window.showInputBox(githubTokenOptions); const newToken = await vscode.window.showInputBox(githubTokenOptions);
@ -383,4 +393,4 @@ async function queryForGithubToken(state: PersistentState): Promise<void> {
log.info("Storing new github token"); log.info("Storing new github token");
await state.updateGithubToken(newToken); await state.updateGithubToken(newToken);
} }
} }