if (!shouldCheckForNewNightly) return;
}
- const release = await performDownloadWithRetryDialog(async () => {
+ const release = await performDownloadWithRetryDialog(state, async () => {
return await fetchRelease("nightly", state.githubToken);
- }, state).catch((e) => {
+ }).catch((e) => {
log.error(e);
if (state.releaseId === undefined) { // Show error only for the initial download
vscode.window.showErrorMessage(`Failed to download rust-analyzer nightly ${e}`);
const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
- await performDownloadWithRetryDialog(async () => {
+ await performDownloadWithRetryDialog(state, async () => {
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
await fs.unlink(dest).catch(err => {
if (err.code !== "ENOENT") throw err;
dest,
progressTitle: "Downloading rust-analyzer extension",
});
- }, state);
+ });
await vscode.commands.executeCommand("workbench.extensions.installExtension", vscode.Uri.file(dest));
await fs.unlink(dest);
}
const releaseTag = config.package.releaseTag;
- const release = await performDownloadWithRetryDialog(async () => {
+ const release = await performDownloadWithRetryDialog(state, async () => {
return await fetchRelease(releaseTag, state.githubToken);
- }, state);
+ });
const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
- await performDownloadWithRetryDialog(async () => {
+ await performDownloadWithRetryDialog(state, async () => {
// Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
await fs.unlink(dest).catch(err => {
if (err.code !== "ENOENT") throw err;
gunzip: true,
mode: 0o755
});
- }, state);
+ });
// Patching executable if that's NixOS.
if (await fs.stat("/etc/nixos").then(_ => true).catch(_ => false)) {
return dest;
}
-async function performDownloadWithRetryDialog<T>(downloadFunc: () => Promise<T>, state: PersistentState): Promise<T> {
+async function performDownloadWithRetryDialog<T>(state: PersistentState, downloadFunc: () => Promise<T>): Promise<T> {
while (true) {
try {
return await downloadFunc();
};
const newToken = await vscode.window.showInputBox(githubTokenOptions);
- if (newToken !== undefined) {
- if (newToken === "") {
- log.info("Clearing github token");
- await state.updateGithubToken(undefined);
- } else {
- log.info("Storing new github token");
- await state.updateGithubToken(newToken);
- }
+ if (newToken === undefined) {
+ // The user aborted the dialog => Do not update the stored token
+ return;
+ }
+
+ if (newToken === "") {
+ log.info("Clearing github token");
+ await state.updateGithubToken(undefined);
+ } else {
+ log.info("Storing new github token");
+ await state.updateGithubToken(newToken);
}
}