aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-01-25 18:40:57 +0000
committerGitHub <[email protected]>2021-01-25 18:40:57 +0000
commitaa91a0268bae6deda964a9fdfcbdbd2d8ca5802f (patch)
treea26b4b5cd7f6b0fa5e301103cc8d91b37afbec82 /editors/code/src
parenta37091d2d0175b0999d6383d48f538cdbf0267a0 (diff)
parent03a1da9d469be92a0ec34c8673293811694b8449 (diff)
Merge #7430
7430: Simplify file download code r=matklad a=lnicola This avoids leaving the user with no LSP binary available if their network goes down during the download, and should not keep the current behavior: overwriting a running executable works on Unix and fails on Windows. It also removes the `overwrite` argument, which is always enabled and wasn't working anyway. Nominally closes #3896 (although that's already fixed) Co-authored-by: LaurenČ›iu Nicola <[email protected]>
Diffstat (limited to 'editors/code/src')
-rw-r--r--editors/code/src/main.ts2
-rw-r--r--editors/code/src/net.ts9
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
79export async function download(opts: DownloadOpts) { 78export 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,