From c4a8587f4526a856ec3c1bca73346d332b3a8586 Mon Sep 17 00:00:00 2001 From: Chuan-kai Lin Date: Fri, 14 Feb 2025 12:08:07 -0800 Subject: [PATCH] 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. --- src/tar.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/tar.ts b/src/tar.ts index 056e958e7..e8418a8a2 100644 --- a/src/tar.ts +++ b/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 { 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((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,