From c7f464774901d40483a6edc4f1294e1648dee4d5 Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Wed, 23 Sep 2020 08:37:02 -0700 Subject: Move unlink on download into download function Since this is required by all callsites its easier to have it in the function itself. --- editors/code/src/net.ts | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'editors/code/src/net.ts') diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index cfbe1fd48..e746465d1 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, -- cgit v1.2.3