fix(artifacts): validate only active extraction entries

This commit is contained in:
morluto
2026-10-10 01:45:00 +08:00
parent 7a4f2685d4
commit cfb12e47dc
2 changed files with 64 additions and 20 deletions
+19 -19
View File
@@ -54,12 +54,26 @@ export const extractArtifact = async (
(occurrence.entry_kind === "file" || occurrence.entry_kind === "slice") &&
occurrence.logical_path !== ".",
);
const selectedIds = new Set(
selectedOccurrences.map(({ occurrence_id: id }) => id),
);
const regularPaths = new Set(
selectedOccurrences.map(({ logical_path: path }) => path),
);
const activeOccurrences = selectedOccurrences.filter(({ logical_path }) => {
// Nested members remain represented by their containing regular file;
// only entries exposed by the active reader are materialized.
let path = logical_path;
for (
let slash = path.lastIndexOf("/");
slash >= 0;
slash = path.lastIndexOf("/")
) {
path = path.slice(0, slash);
if (regularPaths.has(path)) return false;
}
return true;
});
const selectedIds = new Set(
activeOccurrences.map(({ occurrence_id: id }) => id),
);
const occurrences = new Map<string, ArtifactOccurrence>();
const neededNodes = new Set<string>();
collectOccurrences(
@@ -75,7 +89,7 @@ export const extractArtifact = async (
occurrences,
nodes,
};
const selected = selectedOccurrences.map((occurrence) => {
const selected = activeOccurrences.map((occurrence) => {
// REA never decrypts archive entries, so an encrypted entry makes the
// complete extraction unsupported rather than the archive invalid.
if (occurrence.encrypted)
@@ -101,25 +115,11 @@ export const extractArtifact = async (
);
return { occurrence, node };
});
const activeSelected = selected.filter(({ occurrence }) => {
// Nested members remain represented by their containing regular file;
// only entries exposed by the active reader are materialized.
let path = occurrence.logical_path;
for (
let slash = path.lastIndexOf("/");
slash >= 0;
slash = path.lastIndexOf("/")
) {
path = path.slice(0, slash);
if (regularPaths.has(path)) return false;
}
return true;
});
return materializeSelection({
input,
sourcePath,
inventory,
selected: activeSelected,
selected,
signal,
});
};