diff options
Diffstat (limited to 'editors/code')
-rw-r--r-- | editors/code/src/main.ts | 2 | ||||
-rw-r--r-- | editors/code/src/net.ts | 9 |
2 files changed, 1 insertions, 10 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 1edb7713d..1900d900a 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts | |||
@@ -208,7 +208,6 @@ async function bootstrapExtension(config: Config, state: PersistentState): Promi | |||
208 | url: artifact.browser_download_url, | 208 | url: artifact.browser_download_url, |
209 | dest, | 209 | dest, |
210 | progressTitle: "Downloading rust-analyzer extension", | 210 | progressTitle: "Downloading rust-analyzer extension", |
211 | overwrite: true, | ||
212 | }); | 211 | }); |
213 | }); | 212 | }); |
214 | 213 | ||
@@ -340,7 +339,6 @@ async function getServer(config: Config, state: PersistentState): Promise<string | |||
340 | progressTitle: "Downloading rust-analyzer server", | 339 | progressTitle: "Downloading rust-analyzer server", |
341 | gunzip: true, | 340 | gunzip: true, |
342 | mode: 0o755, | 341 | mode: 0o755, |
343 | overwrite: true, | ||
344 | }); | 342 | }); |
345 | }); | 343 | }); |
346 | 344 | ||
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts index 3e50d352c..d39dc1baf 100644 --- a/editors/code/src/net.ts +++ b/editors/code/src/net.ts | |||
@@ -73,23 +73,16 @@ interface DownloadOpts { | |||
73 | dest: string; | 73 | dest: string; |
74 | mode?: number; | 74 | mode?: number; |
75 | gunzip?: boolean; | 75 | gunzip?: boolean; |
76 | overwrite?: boolean; | ||
77 | } | 76 | } |
78 | 77 | ||
79 | export async function download(opts: DownloadOpts) { | 78 | export async function download(opts: DownloadOpts) { |
80 | // Put artifact into a temporary file (in the same dir for simplicity) | 79 | // Put artifact into a temporary file (in the same dir for simplicity) |
81 | // to prevent partially downloaded files when user kills vscode | 80 | // to prevent partially downloaded files when user kills vscode |
81 | // This also avoids overwriting running executables | ||
82 | const dest = path.parse(opts.dest); | 82 | const dest = path.parse(opts.dest); |
83 | const randomHex = crypto.randomBytes(5).toString("hex"); | 83 | const randomHex = crypto.randomBytes(5).toString("hex"); |
84 | const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`); | 84 | const tempFile = path.join(dest.dir, `${dest.name}${randomHex}`); |
85 | 85 | ||
86 | if (opts.overwrite) { | ||
87 | // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. | ||
88 | await fs.promises.unlink(opts.dest).catch(err => { | ||
89 | if (err.code !== "ENOENT") throw err; | ||
90 | }); | ||
91 | } | ||
92 | |||
93 | await vscode.window.withProgress( | 86 | await vscode.window.withProgress( |
94 | { | 87 | { |
95 | location: vscode.ProgressLocation.Notification, | 88 | location: vscode.ProgressLocation.Notification, |