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 9c0af20
Showing 1 changed file with 12 additions and 6 deletions.
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 9c0af20

Please sign in to comment.