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.
This commit is contained in:
parent
1c15a48f3f
commit
c4a8587f45
1 changed files with 6 additions and 5 deletions
11
src/tar.ts
11
src/tar.ts
|
|
@ -15,6 +15,7 @@ const MIN_REQUIRED_BSD_TAR_VERSION = "3.4.3";
|
|||
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
|
||||
|
||||
export type TarVersion = {
|
||||
name: string;
|
||||
type: "gnu" | "bsd";
|
||||
version: string;
|
||||
};
|
||||
|
|
@ -39,14 +40,14 @@ async function getTarVersion(): Promise<TarVersion> {
|
|||
throw new Error("Failed to parse output of tar --version.");
|
||||
}
|
||||
|
||||
return { type: "gnu", version: match[1] };
|
||||
return { name: "tar", type: "gnu", version: match[1] };
|
||||
} else if (stdout.includes("bsdtar")) {
|
||||
const match = stdout.match(/bsdtar ([0-9.]+)/);
|
||||
if (!match || !match[1]) {
|
||||
throw new Error("Failed to parse output of tar --version.");
|
||||
}
|
||||
|
||||
return { type: "bsd", version: match[1] };
|
||||
return { name: "tar", type: "bsd", version: match[1] };
|
||||
} else {
|
||||
throw new Error("Unknown tar version");
|
||||
}
|
||||
|
|
@ -162,10 +163,10 @@ export async function extractTarZst(
|
|||
|
||||
args.push("-f", tar instanceof stream.Readable ? "-" : tar, "-C", dest);
|
||||
|
||||
process.stdout.write(`[command]tar ${args.join(" ")}\n`);
|
||||
process.stdout.write(`[command]${tarVersion.name} ${args.join(" ")}\n`);
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const tarProcess = spawn("tar", args, { stdio: "pipe" });
|
||||
const tarProcess = spawn(tarVersion.name, args, { stdio: "pipe" });
|
||||
|
||||
let stdout = "";
|
||||
tarProcess.stdout?.on("data", (data: Buffer) => {
|
||||
|
|
@ -196,7 +197,7 @@ export async function extractTarZst(
|
|||
if (code !== 0) {
|
||||
reject(
|
||||
new CommandInvocationError(
|
||||
"tar",
|
||||
tarVersion.name,
|
||||
args,
|
||||
code ?? undefined,
|
||||
stdout,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue