Skip to content

Commit 4267fa6

Browse files
committed
getTarVersion(): add programName parameter
This commit changes getTarVersion() so that it receives the name of the tar program from the caller instead of using the hardcoded string "tar".
1 parent c4a8587 commit 4267fa6

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/tar.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export type TarVersion = {
2020
version: string;
2121
};
2222

23-
async function getTarVersion(): Promise<TarVersion> {
24-
const tar = await io.which("tar", true);
23+
async function getTarVersion(programName: string): Promise<TarVersion> {
24+
const tar = await io.which(programName, true);
2525
let stdout = "";
2626
const exitCode = await new ToolRunner(tar, ["--version"], {
2727
listeners: {
@@ -31,23 +31,23 @@ async function getTarVersion(): Promise<TarVersion> {
3131
},
3232
}).exec();
3333
if (exitCode !== 0) {
34-
throw new Error("Failed to call tar --version");
34+
throw new Error(`Failed to call ${programName} --version`);
3535
}
3636
// Return whether this is GNU tar or BSD tar, and the version number
3737
if (stdout.includes("GNU tar")) {
3838
const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/);
3939
if (!match || !match[1]) {
40-
throw new Error("Failed to parse output of tar --version.");
40+
throw new Error(`Failed to parse output of ${programName} --version.`);
4141
}
4242

43-
return { name: "tar", type: "gnu", version: match[1] };
43+
return { name: programName, type: "gnu", version: match[1] };
4444
} else if (stdout.includes("bsdtar")) {
4545
const match = stdout.match(/bsdtar ([0-9.]+)/);
4646
if (!match || !match[1]) {
47-
throw new Error("Failed to parse output of tar --version.");
47+
throw new Error(`Failed to parse output of ${programName} --version.`);
4848
}
4949

50-
return { name: "tar", type: "bsd", version: match[1] };
50+
return { name: programName, type: "bsd", version: match[1] };
5151
} else {
5252
throw new Error("Unknown tar version");
5353
}
@@ -64,7 +64,7 @@ export async function isZstdAvailable(
6464
): Promise<ZstdAvailability> {
6565
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
6666
try {
67-
const tarVersion = await getTarVersion();
67+
const tarVersion = await getTarVersion("tar");
6868
const { type, version } = tarVersion;
6969
logger.info(`Found ${type} tar version ${version}.`);
7070
switch (type) {

0 commit comments

Comments
 (0)