diff options
Diffstat (limited to 'editors/code/src/installation')
-rw-r--r-- | editors/code/src/installation/download_artifact.ts | 30 | ||||
-rw-r--r-- | editors/code/src/installation/download_file.ts | 3 | ||||
-rw-r--r-- | editors/code/src/installation/server.ts | 3 |
3 files changed, 14 insertions, 22 deletions
diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts index 356723aba..97e4d67c2 100644 --- a/editors/code/src/installation/download_artifact.ts +++ b/editors/code/src/installation/download_artifact.ts | |||
@@ -1,11 +1,10 @@ | |||
1 | import * as vscode from "vscode"; | 1 | import * as vscode from "vscode"; |
2 | import * as path from "path"; | 2 | import * as path from "path"; |
3 | import { promises as fs } from "fs"; | 3 | import { promises as fs } from "fs"; |
4 | import { strict as assert } from "assert"; | ||
5 | 4 | ||
6 | import { ArtifactReleaseInfo } from "./interfaces"; | 5 | import { ArtifactReleaseInfo } from "./interfaces"; |
7 | import { downloadFile } from "./download_file"; | 6 | import { downloadFile } from "./download_file"; |
8 | import { throttle } from "throttle-debounce"; | 7 | import { assert } from "../util"; |
9 | 8 | ||
10 | /** | 9 | /** |
11 | * Downloads artifact from given `downloadUrl`. | 10 | * Downloads artifact from given `downloadUrl`. |
@@ -20,11 +19,10 @@ export async function downloadArtifact( | |||
20 | installationDir: string, | 19 | installationDir: string, |
21 | displayName: string, | 20 | displayName: string, |
22 | ) { | 21 | ) { |
23 | await fs.mkdir(installationDir).catch(err => assert.strictEqual( | 22 | await fs.mkdir(installationDir).catch(err => assert( |
24 | err?.code, | 23 | err?.code === "EEXIST", |
25 | "EEXIST", | ||
26 | `Couldn't create directory "${installationDir}" to download ` + | 24 | `Couldn't create directory "${installationDir}" to download ` + |
27 | `${artifactFileName} artifact: ${err.message}` | 25 | `${artifactFileName} artifact: ${err?.message}` |
28 | )); | 26 | )); |
29 | 27 | ||
30 | const installationPath = path.join(installationDir, artifactFileName); | 28 | const installationPath = path.join(installationDir, artifactFileName); |
@@ -38,19 +36,15 @@ export async function downloadArtifact( | |||
38 | async (progress, _cancellationToken) => { | 36 | async (progress, _cancellationToken) => { |
39 | let lastPrecentage = 0; | 37 | let lastPrecentage = 0; |
40 | const filePermissions = 0o755; // (rwx, r_x, r_x) | 38 | const filePermissions = 0o755; // (rwx, r_x, r_x) |
41 | await downloadFile(downloadUrl, installationPath, filePermissions, throttle( | 39 | await downloadFile(downloadUrl, installationPath, filePermissions, (readBytes, totalBytes) => { |
42 | 200, | 40 | const newPercentage = (readBytes / totalBytes) * 100; |
43 | /* noTrailing: */ true, | 41 | progress.report({ |
44 | (readBytes, totalBytes) => { | 42 | message: newPercentage.toFixed(0) + "%", |
45 | const newPercentage = (readBytes / totalBytes) * 100; | 43 | increment: newPercentage - lastPrecentage |
46 | progress.report({ | 44 | }); |
47 | message: newPercentage.toFixed(0) + "%", | ||
48 | increment: newPercentage - lastPrecentage | ||
49 | }); | ||
50 | 45 | ||
51 | lastPrecentage = newPercentage; | 46 | lastPrecentage = newPercentage; |
52 | }) | 47 | }); |
53 | ); | ||
54 | } | 48 | } |
55 | ); | 49 | ); |
56 | } | 50 | } |
diff --git a/editors/code/src/installation/download_file.ts b/editors/code/src/installation/download_file.ts index 319cb995c..ee8949d61 100644 --- a/editors/code/src/installation/download_file.ts +++ b/editors/code/src/installation/download_file.ts | |||
@@ -2,8 +2,7 @@ import fetch from "node-fetch"; | |||
2 | import * as fs from "fs"; | 2 | import * as fs from "fs"; |
3 | import * as stream from "stream"; | 3 | import * as stream from "stream"; |
4 | import * as util from "util"; | 4 | import * as util from "util"; |
5 | import { strict as assert } from "assert"; | 5 | import { log, assert } from "../util"; |
6 | import { log } from "../util"; | ||
7 | 6 | ||
8 | const pipeline = util.promisify(stream.pipeline); | 7 | const pipeline = util.promisify(stream.pipeline); |
9 | 8 | ||
diff --git a/editors/code/src/installation/server.ts b/editors/code/src/installation/server.ts index cb5e56844..6a6cf4f8c 100644 --- a/editors/code/src/installation/server.ts +++ b/editors/code/src/installation/server.ts | |||
@@ -1,13 +1,12 @@ | |||
1 | import * as vscode from "vscode"; | 1 | import * as vscode from "vscode"; |
2 | import * as path from "path"; | 2 | import * as path from "path"; |
3 | import { strict as assert } from "assert"; | ||
4 | import { promises as dns } from "dns"; | 3 | import { promises as dns } from "dns"; |
5 | import { spawnSync } from "child_process"; | 4 | import { spawnSync } from "child_process"; |
6 | 5 | ||
7 | import { BinarySource } from "./interfaces"; | 6 | import { BinarySource } from "./interfaces"; |
8 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; | 7 | import { fetchArtifactReleaseInfo } from "./fetch_artifact_release_info"; |
9 | import { downloadArtifact } from "./download_artifact"; | 8 | import { downloadArtifact } from "./download_artifact"; |
10 | import { log } from "../util"; | 9 | import { log, assert } from "../util"; |
11 | 10 | ||
12 | export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { | 11 | export async function ensureServerBinary(source: null | BinarySource): Promise<null | string> { |
13 | if (!source) { | 12 | if (!source) { |