Skip to content

Commit

Permalink
Ensure destination directory exists when streaming extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
Henry Mercer committed Dec 3, 2024
1 parent d5bcf48 commit b2a4442
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/tar.js

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

2 changes: 1 addition & 1 deletion lib/tar.js.map

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

4 changes: 4 additions & 0 deletions lib/tools-download.js

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

2 changes: 1 addition & 1 deletion lib/tools-download.js.map

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

4 changes: 3 additions & 1 deletion src/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ export async function extractTarZst(

if (tar instanceof stream.Readable) {
tar.pipe(tarProcess.stdin).on("error", (err) => {
reject(new Error(`Error while piping tar stream: ${err}`));
reject(
new Error(`Error while downloading and extracting tar: ${err}`),
);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/tools-download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ async function downloadAndExtractZstdWithStreaming(
tarVersion: tar.TarVersion,
logger: Logger,
): Promise<void> {
// Ensure destination exists
fs.mkdirSync(dest, { recursive: true });

// Add User-Agent header and Authorization header if provided.
headers = Object.assign(
{ "User-Agent": "CodeQL Action" },
authorization ? { authorization } : {},
Expand All @@ -193,6 +197,7 @@ async function downloadAndExtractZstdWithStreaming(
codeqlURL,
{
headers,
// Increase the high water mark to improve performance.
highWaterMark: STREAMING_HIGH_WATERMARK_BYTES,
} as unknown as RequestOptions,
(r) => resolve(r),
Expand Down

0 comments on commit b2a4442

Please sign in to comment.