Skip to content

Commit

Permalink
chore: reduce tar output in the logs
Browse files Browse the repository at this point in the history
  • Loading branch information
aalemayhu committed Dec 5, 2024
1 parent f5aa535 commit 648a540
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/lib/parser/ParserRules.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ describe('ParserRules', () => {
try {
await ParserRules.Load('owner', 'id');
} catch (error) {
expect(error).toBeInstanceOf(TypeError);
expect(error.message).toContain('Cannot read properties of undefined');
const typedError = error as TypeError;
expect(typedError).toBeInstanceOf(TypeError);
expect(typedError.message).toContain('Cannot read properties of undefined');
}
});
});
});
18 changes: 12 additions & 6 deletions src/lib/zip/fallback/unpack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { spawn } from 'node:child_process';
import { createWriteStream } from 'node:fs';
import { join } from 'node:path';

import { listFiles } from './listFiles';
import { File } from './types';
Expand All @@ -7,15 +9,19 @@ const TAR_PATH = '/usr/bin/bsdtar';

export function unpack(filePath: string, workspace: string): Promise<File[]> {
return new Promise((resolve, reject) => {
const stdoutLogPath = join(workspace, 'tar_stdout.log');
const stderrLogPath = join(workspace, 'tar_stderr.log');

const stdoutStream = createWriteStream(stdoutLogPath, { flags: 'a' });
const stderrStream = createWriteStream(stderrLogPath, { flags: 'a' });

const decompressProcess = spawn(TAR_PATH, ['xvf', filePath], {
cwd: workspace,
});
decompressProcess.stdout.on('data', (data) => {
console.log(`tar output: ${data}`);
});
decompressProcess.stderr.on('data', (data) => {
console.error(`tar error: ${data}`);
});

decompressProcess.stdout.pipe(stdoutStream);
decompressProcess.stderr.pipe(stderrStream);

decompressProcess.on('close', () => {
// We are not reading the status code because we support partial extraction
listFiles(workspace).then(resolve).catch(reject);
Expand Down

0 comments on commit 648a540

Please sign in to comment.