Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check zstd is on the path in addition to tar version #2526

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for knowing if zstd is available if we can't figure out what tar version is available?

Actually, I'm not sure what the use case for having foundZstdBinary as part of the interface is. Is this for telemetry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for knowing if zstd is available if we can't figure out what tar version is available?

If we can't figure out what tar version is available, we want to fall back to gzip.

Actually, I'm not sure what the use case for having foundZstdBinary as part of the interface is. Is this for telemetry?

Yes, this is just to help us understand how much of the time zstd wasn't available due to the tar version and how much of the time it wasn't available due to not being able to find a zstd binary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

}
}

Expand Down
Loading