diff --git a/src/domain/appleApplication.test.ts b/src/domain/appleApplication.test.ts index b9e1041b0..47c45a746 100644 --- a/src/domain/appleApplication.test.ts +++ b/src/domain/appleApplication.test.ts @@ -309,6 +309,18 @@ describe("Apple bundle layouts and containers", () => { expect( result.bundles.find(({ path }) => path === framework)?.info_plist_path, ).toBeNull(); + // Files beside the only real version are not versions. + const withFiles = project( + inventoryEvidence("zip", "Fixture.zip", [ + macho("Fixture.app/Contents/MacOS/Fixture"), + { path: `${framework}/Versions/A/Resources/Info.plist` }, + { path: `${framework}/Versions/.DS_Store` }, + { path: `${framework}/Versions/Current`, kind: "symlink" }, + ]), + ); + expect( + withFiles.bundles.find(({ path }) => path === framework)?.info_plist_path, + ).toBe(`${framework}/Versions/A/Resources/Info.plist`); // Only A has a plist, but Versions/Current may select B. const onlyA = project( inventoryEvidence("zip", "Fixture.zip", [ diff --git a/src/domain/appleBundleAnatomy.ts b/src/domain/appleBundleAnatomy.ts index 766f1b515..f98def7c6 100644 --- a/src/domain/appleBundleAnatomy.ts +++ b/src/domain/appleBundleAnatomy.ts @@ -141,14 +141,18 @@ export const detectBundles = ( interface Tree { readonly children: ReadonlyMap>; readonly files: ReadonlyMap; + /** Paths observed as directories, or implied by a deeper path. */ + readonly directories: ReadonlySet; } const indexTree = (entries: readonly Entry[]): Tree => { const children = new Map>(); const files = new Map(); + const directories = new Set(); for (const { path, kind, component } of entries) { if (isSidecar(path)) continue; if (kind === "file" && component !== undefined) files.set(path, component); + if (kind === "directory") directories.add(path); const segments = path.split("/"); let parent = ""; for (const segment of segments) { @@ -156,9 +160,10 @@ const indexTree = (entries: readonly Entry[]): Tree => { names.add(segment); children.set(parent, names); parent = joinPath(parent, segment); + if (parent !== path) directories.add(parent); } } - return { children, files }; + return { children, files, directories }; }; const joinPath = (directory: string, name: string): string => @@ -223,9 +228,12 @@ const contentDirectories = ( if (layout === "macos-deep") return [joinPath(directory, "Contents")]; if (layout === "shallow") return [directory]; const versions = joinPath(directory, "Versions"); + // Only real version directories count: Current is a symlink, and files + // such as .DS_Store are not versions. return [...(tree.children.get(versions) ?? [])] .filter((version) => version !== "Current") .map((version) => joinPath(versions, version)) + .filter((version) => tree.directories.has(version)) .sort(compare); };