aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
authorMatthias Einwag <[email protected]>2020-09-23 16:37:02 +0100
committerMatthias Einwag <[email protected]>2020-09-23 16:37:02 +0100
commitc7f464774901d40483a6edc4f1294e1648dee4d5 (patch)
tree11b1afe2df88b9909db0155bb384ae4ef486ac4c /editors/code/src
parentdf4d59512e496ff010c8710e8ea8e2db4a7f4822 (diff)
Move unlink on download into download function
Since this is required by all callsites its easier to have it in the function itself.
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/main.ts14
-rw-r--r--editors/code/src/net.ts8
2 files changed, 11 insertions, 11 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index f865639a1..2896d90ac 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
200 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix"); 200 const dest = path.join(config.globalStoragePath, "rust-analyzer.vsix");
201 201
202 await downloadWithRetryDialog(state, async () => { 202 await downloadWithRetryDialog(state, async () => {
203 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
204 await fs.unlink(dest).catch(err => {
205 if (err.code !== "ENOENT") throw err;
206 });
207
208 await download({ 203 await download({
209 url: artifact.browser_download_url, 204 url: artifact.browser_download_url,
210 dest, 205 dest,
211 progressTitle: "Downloading rust-analyzer extension", 206 progressTitle: "Downloading rust-analyzer extension",
207 overwrite: true,
212 }); 208 });
213 }); 209 });
214 210
@@ -330,17 +326,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
330 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 326 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
331 327
332 await downloadWithRetryDialog(state, async () => { 328 await downloadWithRetryDialog(state, async () => {
333 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
334 await fs.unlink(dest).catch(err => {
335 if (err.code !== "ENOENT") throw err;
336 });
337
338 await download({ 329 await download({
339 url: artifact.browser_download_url, 330 url: artifact.browser_download_url,
340 dest, 331 dest,
341 progressTitle: "Downloading rust-analyzer server", 332 progressTitle: "Downloading rust-analyzer server",
342 gunzip: true, 333 gunzip: true,
343 mode: 0o755 334 mode: 0o755,
335 overwrite: true,
344 }); 336 });
345 }); 337 });
346 338
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 {
76 dest: string; 76 dest: string;
77 mode?: number; 77 mode?: number;
78 gunzip?: boolean; 78 gunzip?: boolean;
79 overwrite?: boolean,
79} 80}
80 81
81export async function download(opts: DownloadOpts) { 82export async function download(opts: DownloadOpts) {
@@ -85,6 +86,13 @@ export async function download(opts: DownloadOpts) {
85 const randomHex = crypto.randomBytes(5).toString("hex"); 86 const randomHex = crypto.randomBytes(5).toString("hex");
86 const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`); 87 const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`);
87 88
89 if (opts.overwrite) {
90 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
91 await fs.promises.unlink(opts.dest).catch(err => {
92 if (err.code !== "ENOENT") throw err;
93 });
94 }
95
88 await vscode.window.withProgress( 96 await vscode.window.withProgress(
89 { 97 {
90 location: vscode.ProgressLocation.Notification, 98 location: vscode.ProgressLocation.Notification,