Skip to content

Commit c9a70ff

Browse files
authored
Merge pull request #2526 from github/henrymercer/check-zstd-on-path
Check zstd is on the path in addition to tar version
2 parents 56d1975 + d65a176 commit c9a70ff

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

lib/tar.js

Lines changed: 18 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tar.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ export type TarVersion = {
1818
version: string;
1919
};
2020

21+
async function isBinaryAccessible(
22+
binary: string,
23+
logger: Logger,
24+
): Promise<boolean> {
25+
try {
26+
await safeWhich(binary);
27+
logger.debug(`Found ${binary}.`);
28+
return true;
29+
} catch (e) {
30+
logger.debug(`Could not find ${binary}: ${e}`);
31+
return false;
32+
}
33+
}
34+
2135
async function getTarVersion(): Promise<TarVersion> {
2236
const tar = await safeWhich("tar");
2337
let stdout = "";
@@ -53,36 +67,40 @@ async function getTarVersion(): Promise<TarVersion> {
5367

5468
export interface ZstdAvailability {
5569
available: boolean;
70+
foundZstdBinary: boolean;
5671
version?: TarVersion;
5772
}
5873

5974
export async function isZstdAvailable(
6075
logger: Logger,
6176
): Promise<ZstdAvailability> {
77+
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
6278
try {
6379
const tarVersion = await getTarVersion();
6480
const { type, version } = tarVersion;
6581
logger.info(`Found ${type} tar version ${version}.`);
6682
switch (type) {
6783
case "gnu":
6884
return {
69-
available: version >= MIN_REQUIRED_GNU_TAR_VERSION,
85+
available: foundZstdBinary && version >= MIN_REQUIRED_GNU_TAR_VERSION,
86+
foundZstdBinary,
7087
version: tarVersion,
7188
};
7289
case "bsd":
7390
return {
74-
available: version >= MIN_REQUIRED_BSD_TAR_VERSION,
91+
available: foundZstdBinary && version >= MIN_REQUIRED_BSD_TAR_VERSION,
92+
foundZstdBinary,
7593
version: tarVersion,
7694
};
7795
default:
7896
assertNever(type);
7997
}
8098
} catch (e) {
81-
logger.error(
82-
"Failed to determine tar version, therefore will assume zstd may not be available. " +
99+
logger.warning(
100+
"Failed to determine tar version, therefore will assume zstd is not available. " +
83101
`The underlying error was: ${e}`,
84102
);
85-
return { available: false };
103+
return { available: false, foundZstdBinary };
86104
}
87105
}
88106

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy