From 81f0a0744dceda9a566e44f261eedca7941b4ea0 Mon Sep 17 00:00:00 2001 From: mattgodbolt-molty Date: Thu, 11 Jun 2026 15:37:17 -0500 Subject: [PATCH] Address review: error handler on entry streams, no mkdir for skipped entries Attach an error handler to every entry stream so an error while draining a skipped entry rejects the extraction rather than throwing an unhandled 'error' event, and only create parent directories for entries we actually write. Co-Authored-By: Claude Fable 5 --- lib/buildenvsetup/ceconan.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/buildenvsetup/ceconan.ts b/lib/buildenvsetup/ceconan.ts index 8d2c03a2f..c7f4c03a0 100644 --- a/lib/buildenvsetup/ceconan.ts +++ b/lib/buildenvsetup/ceconan.ts @@ -148,6 +148,9 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase { const gunzip = zlib.createGunzip(); extract.on('entry', async (header, stream, next) => { + // Drained streams (skipped entries) have no other error listener; without this an + // entry-stream error would throw as an unhandled 'error' event. + stream.on('error', (error: any) => extract.destroy(error)); try { const filepath = this.getDestinationFilepath(downloadPath, header.name, libId); @@ -164,17 +167,20 @@ export class BuildEnvSetupCeConanDirect extends BuildEnvSetupBase { return; } - if (!this.extractAllToRoot) { - await fs.promises.mkdir(path.dirname(filepath), {recursive: true}); - } - if (header.type !== 'file') { // Only regular files are ever written; symlinks, hardlinks, directories etc // are drained and skipped. Draining also avoids a hang on malformed entries // (e.g. a directory with a non-zero size, whose stream tar-stream never ends). stream.resume(); next(); - } else if (header.size === 0) { + return; + } + + if (!this.extractAllToRoot) { + await fs.promises.mkdir(path.dirname(filepath), {recursive: true}); + } + + if (header.size === 0) { // tar-stream emits no data for zero-length entries (see // https://github.com/mafintosh/tar-stream/issues/145): create empty files // explicitly.