Report progress while extracting CodeQL CLI distribution

This commit is contained in:
Koen Vlaswinkel
2023-12-19 16:53:06 +01:00
parent 8cbd77cf65
commit 6f85894a11
3 changed files with 30 additions and 4 deletions

View File

@@ -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);

View File

@@ -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)}]`,
}); });
}; };

View 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)}]`,
});
};
}