From 32a4ca1fa19bd2e02d4455226958f08962bf7b22 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:40:37 +0100 Subject: [PATCH] fix: read .variants archives as archives A .variants copy is named set.zip., and five checks of a collection path tested endswith(".zip"): the zipped_file contents index skipped all 278 copies (658 member md5s held nowhere else), the pack added them without the member CRC test, and the archive acceptance count gave them -1. They now use is_archive_path. In the index a member a primary archive holds answers with the primary, as the resolver prefers it. --- scripts/core/ziptools.py | 5 ++++- tests/test_zipped_member.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/core/ziptools.py b/scripts/core/ziptools.py index e196b53b5..ef1636cba 100644 --- a/scripts/core/ziptools.py +++ b/scripts/core/ziptools.py @@ -203,7 +203,10 @@ def build_zip_contents_index( ) -> dict: """Build {inner_rom_md5: zip_file_sha1} for ROMs inside ZIP files. - Cached in-process, and on disk per archive sha1 when cache_path is set. + A ``.variants/`` copy counts (``neogeo.zip.1a2b3c4d`` is an archive), and + a member a primary archive holds answers with the primary, as the + resolver prefers it. Cached in-process, and on disk per archive sha1 + when cache_path is set. """ global _zip_contents_cache diff --git a/tests/test_zipped_member.py b/tests/test_zipped_member.py index 8083a4b0c..f2f660b99 100644 --- a/tests/test_zipped_member.py +++ b/tests/test_zipped_member.py @@ -57,6 +57,36 @@ class ZippedMemberIsChecked(unittest.TestCase): self.assertNotIn("trs80.zip", names) +class VariantArchivesAreIndexed(unittest.TestCase): + """A .variants/ copy is named neogeo.zip.: the contents + index skipped every one, so a ROM only such a copy holds answered no + zipped_file pin. A member a primary holds still answers with it.""" + + def test_variant_members_count_and_the_primary_wins(self): + from core import ziptools + + with tempfile.TemporaryDirectory() as tmp: + root = Path(tmp) + primary = root / "bios" / "set.zip" + variant = root / "bios" / ".variants" / "set.zip.1a2b3c4d" + variant.parent.mkdir(parents=True) + with zipfile.ZipFile(primary, "w") as zf: + zf.writestr("shared.rom", b"shared") + with zipfile.ZipFile(variant, "w") as zf: + zf.writestr("shared.rom", b"shared") + zf.writestr("own.rom", b"own") + files = {} + # The variant first, as a database may list it. + for path in (variant, primary): + data = path.read_bytes() + files[hashlib.sha1(data).hexdigest()] = {"path": str(path), "name": path.name} + sha1_of = {entry["path"]: sha1 for sha1, entry in files.items()} + ziptools._zip_contents_cache = None + index = build_zip_contents_index({"files": files}, cache_path=None) + self.assertEqual(index[hashlib.md5(b"own").hexdigest()], sha1_of[str(variant)]) + self.assertEqual(index[hashlib.md5(b"shared").hexdigest()], sha1_of[str(primary)]) + + class PackIntegrityChecksTheMember(unittest.TestCase): """Step 6 skipped a zipped_file entry without md5 and matched a cut md5