From a96a0a4641f0f491c3d28dffe21621acd5e9bcfe Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Mon, 23 Nov 2026 22:25:33 +0100 Subject: [PATCH] fix: identity scan walks only collection files --- scripts/resolve/identity.py | 9 +++++---- tests/test_identity.py | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/resolve/identity.py b/scripts/resolve/identity.py index dad2b9659..385da42a0 100644 --- a/scripts/resolve/identity.py +++ b/scripts/resolve/identity.py @@ -18,8 +18,9 @@ from __future__ import annotations from dataclasses import dataclass from pathlib import Path -from core.paths import BIOS_DIR +from core.collectionfiles import collection_files from core.hashing import file_digest +from core.paths import BIOS_DIR from resolve.ownership import maker_of_relative @@ -69,12 +70,12 @@ def scan(bios_dir: str = BIOS_DIR) -> list[Duplicate]: Only files that share a size can share a content, so a size held by one file is never read: hashing the whole tree read 18 GB on every pipeline. + The walk is the database scan's: a copy under `.cache/` is no identity. """ by_size: dict[int, list[Path]] = {} root = Path(bios_dir) - for path in sorted(root.rglob("*")): - if path.is_file(): - by_size.setdefault(path.stat().st_size, []).append(path) + for path in collection_files(root): + by_size.setdefault(path.stat().st_size, []).append(path) by_content: dict[str, list[Path]] = {} for paths in by_size.values(): if len(paths) < 2: diff --git a/tests/test_identity.py b/tests/test_identity.py index b006e421d..60fc06243 100644 --- a/tests/test_identity.py +++ b/tests/test_identity.py @@ -53,6 +53,14 @@ class TestCrossVendorDuplicates(unittest.TestCase): self._write("Sinclair/ZX Spectrum/48.rom", b"rom") self.assertEqual(self._scan(), []) + def test_a_copy_outside_the_collection_is_no_identity(self): + # The database scan leaves .cache/ and hidden files out: a stray + # copy there is not a second name for the dump. + self._write("Commodore/Amiga/kickstart.rom", b"kick") + self._write(".cache/Sega/cartridge.bin", b"kick") + self._write("Sega/Saturn/.cartridge.bin", b"kick") + self.assertEqual(self._scan(), []) + def test_an_explained_crossing_is_silent(self): self._write("Magnavox/Odyssey2/o2rom.bin", b"odyssey") self._write("Philips/Videopac/O2.bin", b"odyssey")