Skip to content

Commit

Permalink
Check zstd is on the path in addition to tar version
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Oct 4, 2024
1 parent 46d955c commit 057e1ec
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 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.

26 changes: 22 additions & 4 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(
logger.warning(
"Failed to determine tar version, therefore will assume zstd may not be available. " +
`The underlying error was: ${e}`,
);
return { available: false };
return { available: false, foundZstdBinary };
}
}

Expand Down

0 comments on commit 057e1ec

Please sign in to comment.