diff --git a/src/artifacts/CpioArtifactReader.ts b/src/artifacts/CpioArtifactReader.ts index a3235ccd2..ec3cc13be 100644 --- a/src/artifacts/CpioArtifactReader.ts +++ b/src/artifacts/CpioArtifactReader.ts @@ -355,18 +355,26 @@ export class CpioArtifactReader implements ArtifactReader { if (header.fileSize > MAX_SYMLINK_TARGET_BYTES) await drain(this.#verified(source, header, raw)); else target = await this.#collect(source, header, raw); - if (path !== undefined) + if (path !== undefined) { + let limitation: string; + if (target === undefined) + limitation = `Symlink target of ${header.fileSize} bytes exceeds ${MAX_SYMLINK_TARGET_BYTES} bytes and was not read.`; + else { + try { + limitation = `Symlink target: ${new TextDecoder("utf-8", { fatal: true }).decode(target)}`; + } catch { + limitation = + "Symlink target is not valid UTF-8 and was not decoded; the archived bytes are preserved only as a byte count."; + } + } yield entryOf({ path, kind: "symlink", key, header, - limitations: [ - target === undefined - ? `Symlink target of ${header.fileSize} bytes exceeds ${MAX_SYMLINK_TARGET_BYTES} bytes and was not read.` - : `Symlink target: ${target.toString("utf8")}`, - ], + limitations: [limitation], }); + } return; } if ( diff --git a/src/artifacts/extraction/ArtifactExtraction.ts b/src/artifacts/extraction/ArtifactExtraction.ts index fd706f90b..6e7fe767e 100644 --- a/src/artifacts/extraction/ArtifactExtraction.ts +++ b/src/artifacts/extraction/ArtifactExtraction.ts @@ -156,14 +156,17 @@ const materializeSelection = async ({ const path = normalizeArtifactPath( frame.prefix === "" ? entry.path : `${frame.prefix}/${entry.path}`, ); - registry.add(path, entry.kind); // Traverse expanded PKG Payload/Scripts like inventory does, so nested - // members are materialized instead of silently skipped. - if ( + // members are materialized instead of silently skipped. An expanded + // member acts as a container: register it as a directory and leave its + // archive bytes to its children, since a file and a directory cannot + // share one output path. + const expandable = entry.nestedArchive === "gzip-cpio" && !entry.encrypted && - entry.contentUnavailable !== true - ) { + entry.contentUnavailable !== true; + registry.add(path, expandable ? "directory" : entry.kind); + if (expandable) { const parent = frame.reader; const nested = new CpioArtifactReader((nestedSignal) => parent.open(entry, nestedSignal), @@ -174,6 +177,7 @@ const materializeSelection = async ({ iterator: nested.entries(signal)[Symbol.asyncIterator](), owned: true, }); + continue; } const selectedItem = byPath.get(path); if (selectedItem === undefined) {