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