Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/entry-points.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/tar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test("extractTarZst rejects if the input stream errors", async (t) => {
const promise = extractTarZst(
archive,
path.join(tmpDir, "dest"),
{ type: "gnu", version: "1.34" },
{ type: "gnu", version: "1.34", path: "tar" },
new RecordingLogger(),
);

Expand Down
14 changes: 8 additions & 6 deletions src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const MIN_REQUIRED_GNU_TAR_VERSION = "1.31";
export type TarVersion = {
type: "gnu" | "bsd";
version: string;
/** Path to the `tar` executable that reported this version. */
path: string;
};

async function getTarVersion(): Promise<TarVersion> {
Expand All @@ -39,14 +41,14 @@ async function getTarVersion(): Promise<TarVersion> {
throw new Error("Failed to parse output of tar --version.");
}

return { type: "gnu", version: match[1] };
return { type: "gnu", version: match[1], path: tar };
} else if (stdout.includes("bsdtar")) {
const match = stdout.match(/bsdtar ([0-9.]+)/);
if (!match?.[1]) {
throw new Error("Failed to parse output of tar --version.");
}

return { type: "bsd", version: match[1] };
return { type: "bsd", version: match[1], path: tar };
} else {
throw new Error("Unknown tar version");
}
Expand Down Expand Up @@ -171,10 +173,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.path} ${args.join(" ")}\n`);

await new Promise<void>((resolve, reject) => {
const tarProcess = spawn("tar", args, { stdio: "pipe" });
const tarProcess = spawn(tarVersion.path, args, { stdio: "pipe" });

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll make a follow up improvement to the binary planting custom CodeQL query to cover this.

Comment on lines -174 to +179

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a change in this PR, but is there a reason here why this doesn't use e.g. ToolRunner?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Afaict, we can't pipe in a HTTP stream with ToolRunner.


let stdout = "";
tarProcess.stdout?.on("data", (data: Buffer) => {
Expand Down Expand Up @@ -210,11 +212,11 @@ export async function extractTarZst(
if (code !== 0) {
reject(
new CommandInvocationError(
"tar",
tarVersion.path,
args,
code ?? undefined,
stdout,
stderr,
stdout,
),
);
}
Expand Down
10 changes: 5 additions & 5 deletions src/tools-download.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ test.serial(
destination,
undefined,
{},
{ type: "gnu", version: "1.34" },
{ type: "gnu", version: "1.34", path: "tar" },
new RecordingLogger(),
);

Expand Down Expand Up @@ -103,7 +103,7 @@ test.serial(
destination,
undefined,
{},
{ type: "gnu", version: "1.34" },
{ type: "gnu", version: "1.34", path: "tar" },
new RecordingLogger(),
),
{
Expand Down Expand Up @@ -147,7 +147,7 @@ test.serial(
destination,
undefined,
{},
{ type: "gnu", version: "1.34" },
{ type: "gnu", version: "1.34", path: "tar" },
new RecordingLogger(),
);

Expand Down Expand Up @@ -187,7 +187,7 @@ test.serial(
destination,
undefined,
{},
{ type: "gnu", version: "1.34" },
{ type: "gnu", version: "1.34", path: "tar" },
new RecordingLogger(),
);

Expand Down Expand Up @@ -235,7 +235,7 @@ test.serial(
path.join(tmpDir, "codeql"),
undefined,
{},
{ type: "gnu", version: "1.34" },
{ type: "gnu", version: "1.34", path: "tar" },
new RecordingLogger(),
);

Expand Down
Loading