fix(artifacts): preserve archive entry types and host paths (#581)

This commit is contained in:
morluto
2026-10-05 23:19:04 +08:00
committed by GitHub
parent f73bb0fe11
commit 28e0f4e9ec
5 changed files with 153 additions and 5 deletions
@@ -255,6 +255,10 @@ const expectedInventory = (
"integrity",
`Artifact inventory node is missing: ${occurrence.logical_path}`,
);
// Inventory occurrences can have content identities for directories too.
// Suffixes only describe file candidates; a directory such as
// node_modules/@zip.js remains a graph node and must never be opened.
if (occurrence.entry_kind !== "file") continue;
if (occurrence.logical_path.toLowerCase().endsWith(".asar"))
containers.set(occurrence.logical_path, {
path: occurrence.logical_path,
+16 -3
View File
@@ -1,3 +1,4 @@
import { sep } from "node:path";
import { Readable } from "node:stream";
import { extractFile, listPackage, statFile, uncache } from "@electron/asar";
@@ -33,11 +34,18 @@ export class AsarArtifactReader implements ArtifactReader {
}
for (const listed of paths) {
abortIfNeeded(signal);
const path = listed.replace(/^\/+|\/+$/gu, "");
// @electron/asar returns paths assembled with the host path module.
// Keep that spelling for its API calls, but expose archive paths with
// portable separators. On POSIX, backslashes can be literal filename
// characters and must remain untouched.
const path = toArtifactPath(listed);
if (path.length === 0) continue;
const providerPath = listed.startsWith(sep)
? listed.slice(sep.length)
: listed;
let metadata: ReturnType<typeof statFile>;
try {
metadata = statFile(this.path, path, false);
metadata = statFile(this.path, providerPath, false);
} catch (cause: unknown) {
throw asarFailure(this.path, `stat ${path}`, cause);
}
@@ -68,7 +76,7 @@ export class AsarArtifactReader implements ArtifactReader {
: [
"Official ASAR extraction buffers each individually bounded file.",
],
adapterKey: path,
adapterKey: providerPath,
};
}
}
@@ -119,6 +127,11 @@ const abortIfNeeded = (signal?: AbortSignal): void => {
throw new ArtifactReaderFailure("cancelled", "ASAR operation cancelled");
};
const toArtifactPath = (listed: string): string => {
const portable = sep === "\\" ? listed.replaceAll("\\", "/") : listed;
return portable.replace(/^\/+|\/+$/gu, "");
};
const asarFailure = (
path: string,
operation: string,