Merge pull request #3152 from github/koesie10/distribution-yauzl
Switch to `yauzl` for CodeQL CLI
This commit is contained in:
@@ -15,7 +15,6 @@ import {
|
||||
import {
|
||||
codeQlLauncherName,
|
||||
deprecatedCodeQlLauncherName,
|
||||
extractZipArchive,
|
||||
getRequiredAssetName,
|
||||
} from "../common/distribution";
|
||||
import {
|
||||
@@ -26,6 +25,7 @@ import {
|
||||
showAndLogErrorMessage,
|
||||
showAndLogWarningMessage,
|
||||
} from "../common/logging";
|
||||
import { unzipToDirectory } from "../common/unzip";
|
||||
|
||||
/**
|
||||
* distribution.ts
|
||||
@@ -420,7 +420,7 @@ class ExtensionSpecificDistributionManager {
|
||||
void extLogger.log(
|
||||
`Extracting CodeQL CLI to ${this.getDistributionStoragePath()}`,
|
||||
);
|
||||
await extractZipArchive(archivePath, this.getDistributionStoragePath());
|
||||
await unzipToDirectory(archivePath, this.getDistributionStoragePath());
|
||||
} finally {
|
||||
await remove(tmpDirectory);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import { platform } from "os";
|
||||
import { Open } from "unzipper";
|
||||
import { join } from "path";
|
||||
import { pathExists, chmod } from "fs-extra";
|
||||
|
||||
/**
|
||||
* Get the name of the codeql cli installation we prefer to install, based on our current platform.
|
||||
@@ -19,31 +16,6 @@ export function getRequiredAssetName(): string {
|
||||
}
|
||||
}
|
||||
|
||||
export async function extractZipArchive(
|
||||
archivePath: string,
|
||||
outPath: string,
|
||||
): Promise<void> {
|
||||
const archive = await Open.file(archivePath);
|
||||
await archive.extract({
|
||||
concurrency: 4,
|
||||
path: outPath,
|
||||
});
|
||||
// Set file permissions for extracted files
|
||||
await Promise.all(
|
||||
archive.files.map(async (file) => {
|
||||
// Only change file permissions if within outPath (path.join normalises the path)
|
||||
const extractedPath = join(outPath, file.path);
|
||||
if (
|
||||
extractedPath.indexOf(outPath) !== 0 ||
|
||||
!(await pathExists(extractedPath))
|
||||
) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return chmod(extractedPath, file.externalFileAttributes >>> 16);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
export function codeQlLauncherName(): string {
|
||||
return platform() === "win32" ? "codeql.exe" : "codeql";
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ import { existsSync, createWriteStream, mkdirpSync } from "fs-extra";
|
||||
import { normalize, join } from "path";
|
||||
import {
|
||||
getRequiredAssetName,
|
||||
extractZipArchive,
|
||||
codeQlLauncherName,
|
||||
} from "../../src/common/distribution";
|
||||
import { unzipToDirectory } from "../../src/common/unzip";
|
||||
import fetch from "node-fetch";
|
||||
import supportedCliVersions from "../../supported_cli_versions.json";
|
||||
|
||||
@@ -126,7 +126,7 @@ export async function ensureCli(useCli: boolean) {
|
||||
|
||||
console.log(`Unzipping into '${unzipDir}'`);
|
||||
mkdirpSync(unzipDir);
|
||||
await extractZipArchive(downloadedFilePath, unzipDir);
|
||||
await unzipToDirectory(downloadedFilePath, unzipDir);
|
||||
console.log("Done.");
|
||||
} catch (e) {
|
||||
console.error("Failed to download CLI.");
|
||||
|
||||
Reference in New Issue
Block a user