Report progress while extracting CodeQL CLI distribution
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
import { unzipToDirectoryConcurrently } from "../common/unzip-concurrently";
|
||||
import { reportUnzipProgress } from "../common/vscode/unzip-progress";
|
||||
|
||||
/**
|
||||
* distribution.ts
|
||||
@@ -423,6 +424,12 @@ class ExtensionSpecificDistributionManager {
|
||||
await unzipToDirectoryConcurrently(
|
||||
archivePath,
|
||||
this.getDistributionStoragePath(),
|
||||
progressCallback
|
||||
? reportUnzipProgress(
|
||||
`Extracting CodeQL CLI ${release.name}…`,
|
||||
progressCallback,
|
||||
)
|
||||
: undefined,
|
||||
);
|
||||
} finally {
|
||||
await remove(tmpDirectory);
|
||||
|
||||
@@ -108,6 +108,10 @@ export function withInheritedProgress<R>(
|
||||
}
|
||||
}
|
||||
|
||||
export function readableBytesMb(numBytes: number): string {
|
||||
return `${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a progress monitor that indicates how much progess has been made
|
||||
* reading from a stream.
|
||||
@@ -125,15 +129,13 @@ export function reportStreamProgress(
|
||||
) {
|
||||
if (progress && totalNumBytes) {
|
||||
let numBytesDownloaded = 0;
|
||||
const bytesToDisplayMB = (numBytes: number): string =>
|
||||
`${(numBytes / (1024 * 1024)).toFixed(1)} MB`;
|
||||
const updateProgress = () => {
|
||||
progress({
|
||||
step: numBytesDownloaded,
|
||||
maxStep: totalNumBytes,
|
||||
message: `${messagePrefix} [${bytesToDisplayMB(
|
||||
message: `${messagePrefix} [${readableBytesMb(
|
||||
numBytesDownloaded,
|
||||
)} of ${bytesToDisplayMB(totalNumBytes)}]`,
|
||||
)} of ${readableBytesMb(totalNumBytes)}]`,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
17
extensions/ql-vscode/src/common/vscode/unzip-progress.ts
Normal file
17
extensions/ql-vscode/src/common/vscode/unzip-progress.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { UnzipProgressCallback } from "../unzip";
|
||||
import { ProgressCallback, readableBytesMb } from "./progress";
|
||||
|
||||
export function reportUnzipProgress(
|
||||
messagePrefix: string,
|
||||
progress: ProgressCallback,
|
||||
): UnzipProgressCallback {
|
||||
return ({ bytesExtracted, totalBytes }) => {
|
||||
progress({
|
||||
step: bytesExtracted,
|
||||
maxStep: totalBytes,
|
||||
message: `${messagePrefix} [${readableBytesMb(
|
||||
bytesExtracted,
|
||||
)} of ${readableBytesMb(totalBytes)}]`,
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user