diff --git a/scripts/exporter/misterfpga_exporter.py b/scripts/exporter/misterfpga_exporter.py index 0c2ad443..52e65a7b 100644 --- a/scripts/exporter/misterfpga_exporter.py +++ b/scripts/exporter/misterfpga_exporter.py @@ -93,10 +93,14 @@ class Exporter(BaseExporter): fe = indexed.get(path) if fe is None: continue - self._written.add(id(fe)) md5 = fe.hash("md5") - if md5: - entry["hash"] = md5 + if not md5: + # The record is checked by its md5: where the truth takes the + # entry without one, a new size beside the old hash describes + # no file, and the entry is left as MiSTer wrote it. + continue + self._written.add(id(fe)) + entry["hash"] = md5 size = fe.size() if size: entry["size"] = size diff --git a/tests/test_export_counts.py b/tests/test_export_counts.py index 7e94a6b3..1999d0a4 100644 --- a/tests/test_export_counts.py +++ b/tests/test_export_counts.py @@ -325,6 +325,25 @@ class MisterCountsWhatItWrites(unittest.TestCase): self.assertTrue(exporter.states(held, "md5")) self.assertFalse(exporter.states(absent, "md5")) + def test_a_truth_without_md5_leaves_the_record_whole(self): + # The truth took the entry on a size contradiction and has no md5: + # the render kept MiSTer's hash, wrote the new size, and the summary + # announced the hash cleared. + from export_native import landed_changes # noqa: PLC0415 + + fe = NativeFile("boot.rom", "NES/boot.rom", "nes", + platform={"md5": A, "size": 100}, + truth={"sha1": "f" * 40, "size": 200}) + systems = {"nes": NativeSystem("nes", files=[fe])} + database = {"db_id": "x", "files": { + "games/NES/boot.rom": {"hash": A, "size": 100, "url": "u"}}} + exporter = Mister() + produced = exporter.render(systems, None, {"bios_db.json": json.dumps(database)}) + written = json.loads(produced["bios_db.json"])["files"]["games/NES/boot.rom"] + self.assertEqual((written["hash"], written["size"]), (A, 100)) + changes = landed_changes(exporter, systems) + self.assertEqual((changes.cleared, changes.resized), ([], [])) + class OneMd5FormatsAddWhole(unittest.TestCase): def test_an_addition_with_several_md5_is_refused(self):