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";
|
const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
|
||||||
|
|
||||||
export type TarVersion = {
|
export type TarVersion = {
|
||||||
|
name: string;
|
||||||
type: "gnu" | "bsd";
|
type: "gnu" | "bsd";
|
||||||
version: string;
|
version: string;
|
||||||
};
|
};
|
||||||
|
|
@ -39,14 +40,14 @@ async function getTarVersion(): Promise<TarVersion> {
|
||||||
throw new Error("Failed to parse output of tar --version.");
|
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")) {
|
} else if (stdout.includes("bsdtar")) {
|
||||||
const match = stdout.match(/bsdtar ([0-9.]+)/);
|
const match = stdout.match(/bsdtar ([0-9.]+)/);
|
||||||
if (!match || !match[1]) {
|
if (!match || !match[1]) {
|
||||||
throw new Error("Failed to parse output of tar --version.");
|
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 {
|
} else {
|
||||||
throw new Error("Unknown tar version");
|
throw new Error("Unknown tar version");
|
||||||
}
|
}
|
||||||
|
|
@ -162,10 +163,10 @@ export async function extractTarZst(
|
||||||
|
|
||||||
args.push("-f", tar instanceof stream.Readable ? "-" : tar, "-C", dest);
|
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) => {
|
await new Promise<void>((resolve, reject) => {
|
||||||
const tarProcess = spawn("tar", args, { stdio: "pipe" });
|
const tarProcess = spawn(tarVersion.name, args, { stdio: "pipe" });
|
||||||
|
|
||||||
let stdout = "";
|
let stdout = "";
|
||||||
tarProcess.stdout?.on("data", (data: Buffer) => {
|
tarProcess.stdout?.on("data", (data: Buffer) => {
|
||||||
|
|
@ -196,7 +197,7 @@ export async function extractTarZst(
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
reject(
|
reject(
|
||||||
new CommandInvocationError(
|
new CommandInvocationError(
|
||||||
"tar",
|
tarVersion.name,
|
||||||
args,
|
args,
|
||||||
code ?? undefined,
|
code ?? undefined,
|
||||||
stdout,
|
stdout,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue