aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/code/src/main.ts17
-rw-r--r--editors/code/src/net.ts16
2 files changed, 17 insertions, 16 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index eda95ae5c..bd99d696a 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -274,13 +274,13 @@ async function getServer(config: Config, state: PersistentState): Promise<string
274 }; 274 };
275 if (config.package.releaseTag === null) return "rust-analyzer"; 275 if (config.package.releaseTag === null) return "rust-analyzer";
276 276
277 let binaryName: string | undefined = undefined; 277 let platform: string | undefined;
278 if (process.arch === "x64" || process.arch === "ia32") { 278 if (process.arch === "x64" || process.arch === "ia32") {
279 if (process.platform === "linux") binaryName = "rust-analyzer-linux"; 279 if (process.platform === "linux") platform = "linux";
280 if (process.platform === "darwin") binaryName = "rust-analyzer-mac"; 280 if (process.platform === "darwin") platform = "mac";
281 if (process.platform === "win32") binaryName = "rust-analyzer-windows.exe"; 281 if (process.platform === "win32") platform = "windows";
282 } 282 }
283 if (binaryName === undefined) { 283 if (platform === undefined) {
284 vscode.window.showErrorMessage( 284 vscode.window.showErrorMessage(
285 "Unfortunately we don't ship binaries for your platform yet. " + 285 "Unfortunately we don't ship binaries for your platform yet. " +
286 "You need to manually clone rust-analyzer repository and " + 286 "You need to manually clone rust-analyzer repository and " +
@@ -291,8 +291,8 @@ async function getServer(config: Config, state: PersistentState): Promise<string
291 ); 291 );
292 return undefined; 292 return undefined;
293 } 293 }
294 294 const ext = platform === "windows" ? ".exe" : "";
295 const dest = path.join(config.globalStoragePath, binaryName); 295 const dest = path.join(config.globalStoragePath, `rust-analyzer-${platform}${ext}`);
296 const exists = await fs.stat(dest).then(() => true, () => false); 296 const exists = await fs.stat(dest).then(() => true, () => false);
297 if (!exists) { 297 if (!exists) {
298 await state.updateServerVersion(undefined); 298 await state.updateServerVersion(undefined);
@@ -309,7 +309,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
309 } 309 }
310 310
311 const release = await fetchRelease(config.package.releaseTag); 311 const release = await fetchRelease(config.package.releaseTag);
312 const artifact = release.assets.find(artifact => artifact.name === binaryName); 312 const artifact = release.assets.find(artifact => artifact.name === `rust-analyzer-${platform}.gz`);
313 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`); 313 assert(!!artifact, `Bad release: ${JSON.stringify(release)}`);
314 314
315 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error. 315 // Unlinking the exe file before moving new one on its place should prevent ETXTBSY error.
@@ -321,6 +321,7 @@ async function getServer(config: Config, state: PersistentState): Promise<string
321 url: artifact.browser_download_url, 321 url: artifact.browser_download_url,
322 dest, 322 dest,
323 progressTitle: "Downloading rust-analyzer server", 323 progressTitle: "Downloading rust-analyzer server",
324 gunzip: true,
324 mode: 0o755 325 mode: 0o755
325 }); 326 });
326 327
diff --git a/editors/code/src/net.ts b/editors/code/src/net.ts
index 866092882..53c9e91cd 100644
--- a/editors/code/src/net.ts
+++ b/editors/code/src/net.ts
@@ -3,6 +3,7 @@ import * as vscode from "vscode";
3import * as stream from "stream"; 3import * as stream from "stream";
4import * as crypto from "crypto"; 4import * as crypto from "crypto";
5import * as fs from "fs"; 5import * as fs from "fs";
6import * as zlib from "zlib";
6import * as util from "util"; 7import * as util from "util";
7import * as path from "path"; 8import * as path from "path";
8import { log, assert } from "./util"; 9import { log, assert } from "./util";
@@ -65,6 +66,7 @@ interface DownloadOpts {
65 url: string; 66 url: string;
66 dest: string; 67 dest: string;
67 mode?: number; 68 mode?: number;
69 gunzip?: boolean;
68} 70}
69 71
70export async function download(opts: DownloadOpts) { 72export async function download(opts: DownloadOpts) {
@@ -82,7 +84,7 @@ export async function download(opts: DownloadOpts) {
82 }, 84 },
83 async (progress, _cancellationToken) => { 85 async (progress, _cancellationToken) => {
84 let lastPercentage = 0; 86 let lastPercentage = 0;
85 await downloadFile(opts.url, tempFile, opts.mode, (readBytes, totalBytes) => { 87 await downloadFile(opts.url, tempFile, opts.mode, !!opts.gunzip, (readBytes, totalBytes) => {
86 const newPercentage = (readBytes / totalBytes) * 100; 88 const newPercentage = (readBytes / totalBytes) * 100;
87 progress.report({ 89 progress.report({
88 message: newPercentage.toFixed(0) + "%", 90 message: newPercentage.toFixed(0) + "%",
@@ -97,16 +99,11 @@ export async function download(opts: DownloadOpts) {
97 await fs.promises.rename(tempFile, opts.dest); 99 await fs.promises.rename(tempFile, opts.dest);
98} 100}
99 101
100/**
101 * Downloads file from `url` and stores it at `destFilePath` with `mode` (unix permissions).
102 * `onProgress` callback is called on recieveing each chunk of bytes
103 * to track the progress of downloading, it gets the already read and total
104 * amount of bytes to read as its parameters.
105 */
106async function downloadFile( 102async function downloadFile(
107 url: string, 103 url: string,
108 destFilePath: fs.PathLike, 104 destFilePath: fs.PathLike,
109 mode: number | undefined, 105 mode: number | undefined,
106 gunzip: boolean,
110 onProgress: (readBytes: number, totalBytes: number) => void 107 onProgress: (readBytes: number, totalBytes: number) => void
111): Promise<void> { 108): Promise<void> {
112 const res = await fetch(url); 109 const res = await fetch(url);
@@ -130,7 +127,10 @@ async function downloadFile(
130 }); 127 });
131 128
132 const destFileStream = fs.createWriteStream(destFilePath, { mode }); 129 const destFileStream = fs.createWriteStream(destFilePath, { mode });
133 await pipeline(res.body, destFileStream); 130 const srcStream = gunzip ? res.body.pipe(zlib.createGunzip()) : res.body;
131
132 await pipeline(srcStream, destFileStream);
133
134 await new Promise<void>(resolve => { 134 await new Promise<void>(resolve => {
135 destFileStream.on("close", resolve); 135 destFileStream.on("close", resolve);
136 destFileStream.destroy(); 136 destFileStream.destroy();