Skip to content

Commit 6f85894

Browse files
committed
Report progress while extracting CodeQL CLI distribution
1 parent 8cbd77c commit 6f85894

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

extensions/ql-vscode/src/codeql-cli/distribution.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
showAndLogWarningMessage,
2727
} from "../common/logging";
2828
import { unzipToDirectoryConcurrently } from "../common/unzip-concurrently";
29+
import { reportUnzipProgress } from "../common/vscode/unzip-progress";
2930

3031
/**
3132
* distribution.ts
@@ -423,6 +424,12 @@ class ExtensionSpecificDistributionManager {
423424
await unzipToDirectoryConcurrently(
424425
archivePath,
425426
this.getDistributionStoragePath(),
427+
progressCallback
428+
? reportUnzipProgress(
429+
`Extracting CodeQL CLI ${release.name}…`,
430+
progressCallback,
431+
)
432+
: undefined,
426433
);
427434
} finally {
428435
await remove(tmpDirectory);

extensions/ql-vscode/src/common/vscode/progress.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ export function withInheritedProgress<R>(
108108
}
109109
}
110110

111+
export function readableBytesMb(numBytes: number): string {
112+
return `${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
113+
}
114+
111115
/**
112116
* Displays a progress monitor that indicates how much progess has been made
113117
* reading from a stream.
@@ -125,15 +129,13 @@ export function reportStreamProgress(
125129
) {
126130
if (progress && totalNumBytes) {
127131
let numBytesDownloaded = 0;
128-
const bytesToDisplayMB = (numBytes: number): string =>
129-
`${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
130132
const updateProgress = () => {
131133
progress({
132134
step: numBytesDownloaded,
133135
maxStep: totalNumBytes,
134-
message: `${messagePrefix} [${bytesToDisplayMB(
136+
message: `${messagePrefix} [${readableBytesMb(
135137
numBytesDownloaded,
136-
)} of ${bytesToDisplayMB(totalNumBytes)}]`,
138+
)} of ${readableBytesMb(totalNumBytes)}]`,
137139
});
138140
};
139141

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { UnzipProgressCallback } from "../unzip";
2+
import { ProgressCallback, readableBytesMb } from "./progress";
3+
4+
export function reportUnzipProgress(
5+
messagePrefix: string,
6+
progress: ProgressCallback,
7+
): UnzipProgressCallback {
8+
return ({ bytesExtracted, totalBytes }) => {
9+
progress({
10+
step: bytesExtracted,
11+
maxStep: totalBytes,
12+
message: `${messagePrefix} [${readableBytesMb(
13+
bytesExtracted,
14+
)} of ${readableBytesMb(totalBytes)}]`,
15+
});
16+
};
17+
}

0 commit comments

Comments
 (0)