diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index f865639a14d..2896d90ac94 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -200,15 +200,11 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); await downloadWithRetryDialog(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; - }); - await download({ url: artifact.browser_download_url, dest, progressTitle: "Downloading rust-analyzer extension", + overwrite: true, }); }); @@ -330,17 +326,13 @@ async function getServer(config: Config, state: PersistentState): Promise { - // 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; - }); - await download({ url: artifact.browser_download_url, dest, progressTitle: "Downloading rust-analyzer server", gunzip: true, - mode: 0o755 + mode: 0o755, + overwrite: true, }); }); diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index cfbe1fd486b..e746465d1d3 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts @@ -76,6 +76,7 @@ interface DownloadOpts { dest: string; mode?: number; gunzip?: boolean; + overwrite?: boolean, } export async function download(opts: DownloadOpts) { @@ -85,6 +86,13 @@ export async function download(opts: DownloadOpts) { const randomHex = crypto.randomBytes(5).toString("hex"); const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`); + if (opts.overwrite) { + // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. + await fs.promises.unlink(opts.dest).catch(err => { + if (err.code !== "ENOENT") throw err; + }); + } + await vscode.window.withProgress( { location: vscode.ProgressLocation.Notification,