Skip to content

Commit 65a3aa1

Browse files
authored
Revert "Prefer gtar if available"
1 parent acadfed commit 65a3aa1

File tree

4 files changed

+24
-55
lines changed

4 files changed

+24
-55
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ See the [releases page](https://github.com/github/codeql-action/releases) for th
44

55
## [UNRELEASED]
66

7-
- Update the action to prefer `gtar` over `tar` to make zstd archive extraction more robust. [2767](https://github.com/github/codeql-action/pull/2767)
7+
No user facing changes.
88

99
## 3.28.9 - 07 Feb 2025
1010

lib/tar.js

+11-26
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/tar.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/tar.ts

+11-27
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,12 @@ 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;
1918
type: "gnu" | "bsd";
2019
version: string;
2120
};
2221

23-
async function getTarVersion(programName: string): Promise<TarVersion> {
24-
const tar = await io.which(programName, true);
22+
async function getTarVersion(): Promise<TarVersion> {
23+
const tar = await io.which("tar", true);
2524
let stdout = "";
2625
const exitCode = await new ToolRunner(tar, ["--version"], {
2726
listeners: {
@@ -31,43 +30,28 @@ async function getTarVersion(programName: string): Promise<TarVersion> {
3130
},
3231
}).exec();
3332
if (exitCode !== 0) {
34-
throw new Error(`Failed to call ${programName} --version`);
33+
throw new Error("Failed to call tar --version");
3534
}
3635
// Return whether this is GNU tar or BSD tar, and the version number
3736
if (stdout.includes("GNU tar")) {
3837
const match = stdout.match(/tar \(GNU tar\) ([0-9.]+)/);
3938
if (!match || !match[1]) {
40-
throw new Error(`Failed to parse output of ${programName} --version.`);
39+
throw new Error("Failed to parse output of tar --version.");
4140
}
4241

43-
return { name: programName, type: "gnu", version: match[1] };
42+
return { type: "gnu", version: match[1] };
4443
} else if (stdout.includes("bsdtar")) {
4544
const match = stdout.match(/bsdtar ([0-9.]+)/);
4645
if (!match || !match[1]) {
47-
throw new Error(`Failed to parse output of ${programName} --version.`);
46+
throw new Error("Failed to parse output of tar --version.");
4847
}
4948

50-
return { name: programName, type: "bsd", version: match[1] };
49+
return { type: "bsd", version: match[1] };
5150
} else {
5251
throw new Error("Unknown tar version");
5352
}
5453
}
5554

56-
async function pickTarCommand(): Promise<TarVersion> {
57-
// bsdtar 3.5.3 on the macos-14 (arm) action runner image is prone to crash with the following
58-
// error messages when extracting zstd archives:
59-
//
60-
// tar: Child process exited with status 1
61-
// tar: Error exit delayed from previous errors.
62-
//
63-
// To avoid this problem, prefer GNU tar under the name "gtar" if it is available.
64-
try {
65-
return await getTarVersion("gtar");
66-
} catch {
67-
return await getTarVersion("tar");
68-
}
69-
}
70-
7155
export interface ZstdAvailability {
7256
available: boolean;
7357
foundZstdBinary: boolean;
@@ -79,7 +63,7 @@ export async function isZstdAvailable(
7963
): Promise<ZstdAvailability> {
8064
const foundZstdBinary = await isBinaryAccessible("zstd", logger);
8165
try {
82-
const tarVersion = await pickTarCommand();
66+
const tarVersion = await getTarVersion();
8367
const { type, version } = tarVersion;
8468
logger.info(`Found ${type} tar version ${version}.`);
8569
switch (type) {
@@ -178,10 +162,10 @@ export async function extractTarZst(
178162

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

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

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

186170
let stdout = "";
187171
tarProcess.stdout?.on("data", (data: Buffer) => {
@@ -212,7 +196,7 @@ export async function extractTarZst(
212196
if (code !== 0) {
213197
reject(
214198
new CommandInvocationError(
215-
tarVersion.name,
199+
"tar",
216200
args,
217201
code ?? undefined,
218202
stdout,

0 commit comments

Comments
 (0)