Skip to content

Commit

Permalink
Merge pull request #2526 from github/henrymercer/check-zstd-on-path
Browse files Browse the repository at this point in the history
Check zstd is on the path in addition to tar version
  • Loading branch information
henrymercer authored Oct 7, 2024
2 parents 56d1975 + d65a176 commit c9a70ff
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 10 deletions.
22 changes: 18 additions & 4 deletions lib/tar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/tar.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 23 additions & 5 deletions src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ export type TarVersion = {
version: string;
};

async function isBinaryAccessible(
binary: string,
logger: Logger,
): Promise<boolean> {
try {
await safeWhich(binary);
logger.debug(`Found ${binary}.`);
return true;
} catch (e) {
logger.debug(`Could not find ${binary}: ${e}`);
return false;
}
}

async function getTarVersion(): Promise<TarVersion> {
const tar = await safeWhich("tar");
let stdout = "";
Expand Down Expand Up @@ -53,36 +67,40 @@ async function getTarVersion(): Promise<TarVersion> {

export interface ZstdAvailability {
available: boolean;
foundZstdBinary: boolean;
version?: TarVersion;
}

export async function isZstdAvailable(
logger: Logger,
): Promise<ZstdAvailability> {
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
try {
const tarVersion = await getTarVersion();
const { type, version } = tarVersion;
logger.info(`Found ${type} tar version ${version}.`);
switch (type) {
case "gnu":
return {
available: version >= MIN_REQUIRED_GNU_TAR_VERSION,
available: foundZstdBinary && version >= MIN_REQUIRED_GNU_TAR_VERSION,
foundZstdBinary,
version: tarVersion,
};
case "bsd":
return {
available: version >= MIN_REQUIRED_BSD_TAR_VERSION,
available: foundZstdBinary && version >= MIN_REQUIRED_BSD_TAR_VERSION,
foundZstdBinary,
version: tarVersion,
};
default:
assertNever(type);
}
} catch (e) {
logger.error(
"Failed to determine tar version, therefore will assume zstd may not be available. " +
logger.warning(
"Failed to determine tar version, therefore will assume zstd is not available. " +
`The underlying error was: ${e}`,
);
return { available: false };
return { available: false, foundZstdBinary };
}
}

Expand Down

0 comments on commit c9a70ff

Please sign in to comment.