Skip to content

Commit c4a8587

Browse files
committed
Add TarVersion.name field
This refactoring commit records the name of the tar program in the new TarVersion.name field and makes extractTarZst() use the new field instead of the hardcoded name "tar". Code behavior remains unchanged because currently TarVersion.name is always "tar". This is the first step toward supporting a tar program under a different executable name.
1 parent 1c15a48 commit c4a8587

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/tar.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
1515
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
1616

1717
export type TarVersion = {
18+
name: string;
1819
type: "gnu" | "bsd";
1920
version: string;
2021
};
@@ -39,14 +40,14 @@ async function getTarVersion(): Promise<TarVersion> {
3940
throw new Error("Failed to parse output of tar --version.");
4041
}
4142

42-
return { type: "gnu", version: match[1] };
43+
return { name: "tar", type: "gnu", version: match[1] };
4344
} else if (stdout.includes("bsdtar")) {
4445
const match = stdout.match(/bsdtar ([0-9.]+)/);
4546
if (!match || !match[1]) {
4647
throw new Error("Failed to parse output of tar --version.");
4748
}
4849

49-
return { type: "bsd", version: match[1] };
50+
return { name: "tar", type: "bsd", version: match[1] };
5051
} else {
5152
throw new Error("Unknown tar version");
5253
}
@@ -162,10 +163,10 @@ export async function extractTarZst(
162163

163164
args.push("-f", tar instanceof stream.Readable ? "-" : tar, "-C", dest);
164165

165-
process.stdout.write(`[command]tar ${args.join(" ")}\n`);
166+
process.stdout.write(`[command]${tarVersion.name} ${args.join(" ")}\n`);
166167

167168
await new Promise<void>((resolve, reject) => {
168-
const tarProcess = spawn("tar", args, { stdio: "pipe" });
169+
const tarProcess = spawn(tarVersion.name, args, { stdio: "pipe" });
169170

170171
let stdout = "";
171172
tarProcess.stdout?.on("data", (data: Buffer) => {
@@ -196,7 +197,7 @@ export async function extractTarZst(
196197
if (code !== 0) {
197198
reject(
198199
new CommandInvocationError(
199-
"tar",
200+
tarVersion.name,
200201
args,
201202
code ?? undefined,
202203
stdout,

0 commit comments

Comments
 (0)