From a9c0dcac3c82fba750755ba9ff375c2d3da7bc98 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Thu, 19 Nov 2026 06:33:17 +0100 Subject: [PATCH] fix: ship the archive covering a twin md5 pin RetroDECK pins bios/cdibios.zip and bios/stvbios.zip twice, the older MAME set for its mame component and the full set for the RetroArch core. The first pin in system order shipped the smaller set, which current MAME rejects (cdi.cpp:922 needs the slave MCU ROM). The archive whose members cover the other now ships: it serves both readers. --- install/retrodeck.json | 200 +++++++++++++++++----------------- scripts/resolve/collisions.py | 5 +- scripts/resolve/packfiles.py | 54 +++++++-- tests/test_archive_choice.py | 54 +++++++++ wiki/tools.md | 3 + 5 files changed, 206 insertions(+), 110 deletions(-) diff --git a/install/retrodeck.json b/install/retrodeck.json index a11670545..7bd69f3ab 100644 --- a/install/retrodeck.json +++ b/install/retrodeck.json @@ -2366,9 +2366,9 @@ } ], "total_files": 12197, - "total_size": 10572021991, + "total_size": 10572282384, "pack_files": 16110, - "pack_size": 10688709277, + "pack_size": 10688969670, "total_omitted": 340, "omitted_files": [ { @@ -13396,39 +13396,6 @@ ], "truth": false }, - { - "dest": "bios/cdibios.zip", - "sha1": "e7d2a0dad62d6f75bc10f48a376da0a99b764571", - "sha256": "aa8a33813531795de9739b06b65960e0f86cdec504c8452a956d184eac3cdcd4", - "size": 468660, - "repo_path": "bios/Arcade/Arcade/.variants/cdibios.zip.e7d2a0da", - "cores": null, - "systems": [ - "arcade", - "philips-cdi" - ], - "declared_choices": [ - { - "sha1": "e7d2a0dad62d6f75bc10f48a376da0a99b764571", - "sha256": "aa8a33813531795de9739b06b65960e0f86cdec504c8452a956d184eac3cdcd4", - "size": 468660, - "repo_path": "bios/Arcade/Arcade/.variants/cdibios.zip.e7d2a0da", - "systems": [ - "arcade" - ] - }, - { - "sha1": "16072afaa65d1b059346616ac5b5a600c63ff1d1", - "sha256": "b53d206ae81607bf6866411b720ad82ce75122423058ce08c6df84cdc1ca3496", - "size": 472798, - "repo_path": "bios/Philips/CD-i/cdibios.zip", - "systems": [ - "philips-cdi" - ] - } - ], - "truth": false - }, { "dest": "bios/cdu415.zip", "sha1": "d91bdb808f425dca9bec75fd54cd9a634f02dd06", @@ -24502,71 +24469,6 @@ ], "truth": false }, - { - "dest": "bios/stvbios.zip", - "sha1": "330a2ab5ce2e2c29987b2086e021de7aa04aa102", - "sha256": "bbdf6a9ef4bad6bd9ad16f9f7669071dd4ee3bb2387d49124f024ea8dd750f88", - "size": 2699375, - "repo_path": "bios/Arcade/MAME/.variants/stvbios.zip.330a2ab5", - "cores": null, - "systems": [ - "arcade", - "sega-saturn" - ], - "slot": { - "groups": [ - "arcade", - "sega-saturn", - "sega-stv" - ], - "keys": [ - { - "kronos": { - "ranks": [ - null - ], - "sets": [ - "stv-bios" - ] - } - } - ] - }, - "declared_choices": [ - { - "sha1": "330a2ab5ce2e2c29987b2086e021de7aa04aa102", - "sha256": "bbdf6a9ef4bad6bd9ad16f9f7669071dd4ee3bb2387d49124f024ea8dd750f88", - "size": 2699375, - "repo_path": "bios/Arcade/MAME/.variants/stvbios.zip.330a2ab5", - "systems": [ - "arcade" - ] - }, - { - "sha1": "7783ab663bb1a8d62ff60d583674355c2af556b1", - "sha256": "38ceb2792c72770f56aadb1865cf66dc33a3017db1ee05e11c2b2dff397ad39e", - "size": 2955630, - "repo_path": "bios/Arcade/MAME/stvbios.zip", - "systems": [ - "sega-saturn" - ] - } - ], - "alternatives": [ - { - "sha1": "b14bbed4bf459439cf7e96d2f79d7adea5d31448", - "sha256": "1c4970da5f7066dd213d3dca14f7e45408cf667f508f4653025626bb33fbeb14", - "size": 3455065, - "repo_path": "bios/Arcade/Arcade/stvbios.zip", - "cores": [ - "beetle_saturn", - "kronos", - "mednafen_stv" - ] - } - ], - "truth": false - }, { "dest": "bios/sv603.zip", "sha1": "53415c3366e4449751101bbe41e2f8f8b30ebb3e", @@ -31918,6 +31820,39 @@ ], "truth": false }, + { + "dest": "bios/cdibios.zip", + "sha1": "16072afaa65d1b059346616ac5b5a600c63ff1d1", + "sha256": "b53d206ae81607bf6866411b720ad82ce75122423058ce08c6df84cdc1ca3496", + "size": 472798, + "repo_path": "bios/Philips/CD-i/cdibios.zip", + "cores": null, + "systems": [ + "arcade", + "philips-cdi" + ], + "declared_choices": [ + { + "sha1": "16072afaa65d1b059346616ac5b5a600c63ff1d1", + "sha256": "b53d206ae81607bf6866411b720ad82ce75122423058ce08c6df84cdc1ca3496", + "size": 472798, + "repo_path": "bios/Philips/CD-i/cdibios.zip", + "systems": [ + "philips-cdi" + ] + }, + { + "sha1": "e7d2a0dad62d6f75bc10f48a376da0a99b764571", + "sha256": "aa8a33813531795de9739b06b65960e0f86cdec504c8452a956d184eac3cdcd4", + "size": 468660, + "repo_path": "bios/Arcade/Arcade/.variants/cdibios.zip.e7d2a0da", + "systems": [ + "arcade" + ] + } + ], + "truth": false + }, { "dest": "bios/cdi200.rom", "sha1": "d961de803c89b3d1902d656ceb9ce7c02dccb40a", @@ -33307,6 +33242,71 @@ } ] }, + { + "dest": "bios/stvbios.zip", + "sha1": "7783ab663bb1a8d62ff60d583674355c2af556b1", + "sha256": "38ceb2792c72770f56aadb1865cf66dc33a3017db1ee05e11c2b2dff397ad39e", + "size": 2955630, + "repo_path": "bios/Arcade/MAME/stvbios.zip", + "cores": null, + "systems": [ + "arcade", + "sega-saturn" + ], + "slot": { + "groups": [ + "arcade", + "sega-saturn", + "sega-stv" + ], + "keys": [ + { + "kronos": { + "ranks": [ + null + ], + "sets": [ + "stv-bios" + ] + } + } + ] + }, + "declared_choices": [ + { + "sha1": "7783ab663bb1a8d62ff60d583674355c2af556b1", + "sha256": "38ceb2792c72770f56aadb1865cf66dc33a3017db1ee05e11c2b2dff397ad39e", + "size": 2955630, + "repo_path": "bios/Arcade/MAME/stvbios.zip", + "systems": [ + "sega-saturn" + ] + }, + { + "sha1": "330a2ab5ce2e2c29987b2086e021de7aa04aa102", + "sha256": "bbdf6a9ef4bad6bd9ad16f9f7669071dd4ee3bb2387d49124f024ea8dd750f88", + "size": 2699375, + "repo_path": "bios/Arcade/MAME/.variants/stvbios.zip.330a2ab5", + "systems": [ + "arcade" + ] + } + ], + "alternatives": [ + { + "sha1": "b14bbed4bf459439cf7e96d2f79d7adea5d31448", + "sha256": "1c4970da5f7066dd213d3dca14f7e45408cf667f508f4653025626bb33fbeb14", + "size": 3455065, + "repo_path": "bios/Arcade/Arcade/stvbios.zip", + "cores": [ + "beetle_saturn", + "kronos", + "mednafen_stv" + ] + } + ], + "truth": false + }, { "dest": "bios/sega1003.bin", "sha1": "7b23b53d62de0f29a23e423d0fe751dfb469c2fa", diff --git a/scripts/resolve/collisions.py b/scripts/resolve/collisions.py index bac2b43a5..cc5ad16a8 100644 --- a/scripts/resolve/collisions.py +++ b/scripts/resolve/collisions.py @@ -54,8 +54,9 @@ def find_collisions( fold = bool(config.get("case_insensitive_fs", False)) systems = config.get("systems") or {} # The builder lets a hash-constrained declaration that resolves by - # content take the path, else the first it reaches walking the systems - # sorted: the same choice says which file ships. + # content take the path, the archive covering the others when two md5 + # pins tie, else the first it reaches walking the systems sorted: the + # same choice says which file ships. preferred = set( preferred_entries(systems, db, "bios", "", False, zip_contents, True).values() ) diff --git a/scripts/resolve/packfiles.py b/scripts/resolve/packfiles.py index 3a7804a8b..b5e4bd014 100644 --- a/scripts/resolve/packfiles.py +++ b/scripts/resolve/packfiles.py @@ -11,6 +11,7 @@ import os import re import urllib.error import urllib.request +import zipfile from pathlib import Path from model.largefiles import fetch_large_file @@ -482,15 +483,52 @@ def _archive_choice( return fe if accepted(path) > 0 else None -def _hash_choice(resolved: list[tuple[dict, str | None, str]]) -> dict | None: - """The first declaration resolved by md5, else the first by any hash.""" - best = None - for fe, _lp, _st in resolved: - if _lp and _st == "md5_exact": +def _member_crcs(path: str) -> frozenset[int] | None: + """The crc32 of each member of an archive, None when it is no archive.""" + try: + with zipfile.ZipFile(path) as zf: + return frozenset(info.CRC for info in zf.infolist() if not info.is_dir()) + except (OSError, zipfile.BadZipFile): + return None + + +def _covering_archive(candidates: list[tuple[dict, str]]) -> dict | None: + """The archive holding every member each other candidate holds, and more. + + RetroDECK pins bios/cdibios.zip twice: the two-member MAME set for its + mame component, the three-member set for the CD-i core. MAME reads the + members, never the container, and its cdi driver needs all three, so + the larger set serves both readers where the first one serves one. + """ + sets: list[tuple[dict, frozenset[int]]] = [] + for fe, path in candidates: + members = _member_crcs(path) + if members is None: + return None + sets.append((fe, members)) + for fe, members in sets: + others = [m for other, m in sets if other is not fe] + if all(members > m for m in others): return fe - if best is None and _lp and resolution_is_hash_exact(_st): - best = fe - return best + return None + + +def _hash_choice(resolved: list[tuple[dict, str | None, str]]) -> dict | None: + """The declaration resolved by md5, else the first by any hash. + + Two md5 pins on one path are two files for one place: one stays red in + the frontend's check whichever ships, so the archive covering the other + ships, else the first. + """ + by_md5 = [(fe, lp) for fe, lp, st in resolved if lp and st == "md5_exact"] + if by_md5: + if len({lp for _fe, lp in by_md5}) > 1: + covering = _covering_archive(by_md5) + if covering is not None: + return covering + return by_md5[0][0] + return next( + (fe for fe, lp, st in resolved if lp and resolution_is_hash_exact(st)), None) def preferred_entries( diff --git a/tests/test_archive_choice.py b/tests/test_archive_choice.py index 51918b44c..ecb11ce15 100644 --- a/tests/test_archive_choice.py +++ b/tests/test_archive_choice.py @@ -63,6 +63,60 @@ class PreferredArchive(unittest.TestCase): self.assertEqual(path, "bios/b/set.zip") +class TwoPinsOnePath(unittest.TestCase): + """RetroDECK pins bios/cdibios.zip twice, a two-member MAME set and the + three-member set MAME's cdi driver needs. The first pin in system order + shipped the smaller set: the CD-i core and MAME both lacked a ROM.""" + + def _db(self, paths): + files, by_md5, by_name = {}, {}, {} + for path in paths: + data = Path(path).read_bytes() + sha1, md5 = hashlib.sha1(data).hexdigest(), hashlib.md5(data).hexdigest() + files[sha1] = {"path": path, "name": "set.zip", "sha1": sha1, "md5": md5, + "size": len(data)} + by_md5[md5] = sha1 + by_name.setdefault("set.zip", []).append(sha1) + return {"files": files, "indexes": {"by_name": by_name, "by_md5": by_md5, + "by_path_suffix": {}, "by_crc32": {}}} + + def _shipped(self, small_members, large_members): + from resolve import packfiles + + with tempfile.TemporaryDirectory() as tmp: + previous = os.getcwd() + os.chdir(tmp) + self.addCleanup(os.chdir, previous) + for folder, members in (("a", small_members), ("b", large_members)): + Path(f"bios/{folder}").mkdir(parents=True) + with zipfile.ZipFile(f"bios/{folder}/set.zip", "w") as zf: + for name in members: + zf.writestr(name, name.encode() * 16) + db = self._db(["bios/a/set.zip", "bios/b/set.zip"]) + md5 = {f["path"]: f["md5"] for f in db["files"].values()} + systems = { + "arcade": {"files": [{"name": "set.zip", "destination": "set.zip", + "md5": md5["bios/a/set.zip"]}]}, + "cdi": {"files": [{"name": "set.zip", "destination": "set.zip", + "md5": md5["bios/b/set.zip"]}]}, + } + preferred = packfiles.preferred_entries(systems, db, "bios", "", False, {}, True) + chosen = next(fe for s in systems.values() for fe in s["files"] + if id(fe) == preferred["set.zip"]) + path, _status = packfiles.resolve_file(chosen, db, "bios", {}, offline=True) + return path + + def test_the_archive_covering_the_other_ships(self): + self.assertEqual( + self._shipped(["r0.bin", "r1.bin"], ["r0.bin", "r1.bin", "slave.bin"]), + "bios/b/set.zip") + + def test_two_unrelated_archives_keep_the_first(self): + self.assertEqual( + self._shipped(["r0.bin", "r1.bin"], ["r0.bin", "other.bin"]), + "bios/a/set.zip") + + class OneWinnerRuleForEveryReader(unittest.TestCase): """verify passed the data-directory registry to the winner rule, the pack and the manifest passed none: a declaration only a data/ cache satisfies diff --git a/wiki/tools.md b/wiki/tools.md index 4d37081a0..564092423 100644 --- a/wiki/tools.md +++ b/wiki/tools.md @@ -395,6 +395,9 @@ MiSTer resolve no core, so nothing is examined and nothing is listed. A destination the platform's own list declares twice, for two different files, is written under `doubled` (`slots.find_collisions` finds it). One path holds one file, so one of the two checks fails on every install. +When both are archives and one holds every member of the other, that one +ships: a MAME core reads members, never the container, so the larger set +serves both readers. Each declaration carries its system, component, hashes and the file it resolves to, with the emulators the platform runs whose profile reads that file: a member list it holds, a hash it matches, or a name and a