From 3baec1794b8c4535d692f83b197a1b2fe05a840b Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Fri, 9 Oct 2026 22:45:57 +0200 Subject: [PATCH] fix: match a loose dump by crc32 and size --- scripts/provenance_report.py | 8 ++++++++ tests/test_provenance.py | 14 ++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/scripts/provenance_report.py b/scripts/provenance_report.py index bb067b6c..6100a231 100644 --- a/scripts/provenance_report.py +++ b/scripts/provenance_report.py @@ -88,6 +88,13 @@ def build_report(db: dict, snapshots: dict, members: dict | None = None) -> dict by_md5_size = { (entry.get("md5", ""), entry.get("size", 0)) for entry in by_sha1.values() } + # Redump lists some dumps by crc32 alone (ps2-0101jd-20030110, DTL-H10100): + # collected as a loose file it would stay MISSING for good without this. + by_crc32_size = { + (str(entry.get("crc32", "")).lower(), entry.get("size", 0)) + for entry in by_sha1.values() + if entry.get("crc32") + } report = {} for source, snapshot in sorted(snapshots.items()): @@ -98,6 +105,7 @@ def build_report(db: dict, snapshots: dict, members: dict | None = None) -> dict if ( entry.get("sha1") in by_sha1 or (entry.get("md5"), entry.get("size")) in by_md5_size + or (str(entry.get("crc32") or "").lower(), entry.get("size")) in by_crc32_size or _held_in_archive(entry, members) ): matched += 1 diff --git a/tests/test_provenance.py b/tests/test_provenance.py index f8eb24c5..4ef006b8 100644 --- a/tests/test_provenance.py +++ b/tests/test_provenance.py @@ -353,6 +353,20 @@ class TestProvenanceReport(unittest.TestCase): report["redump"]["covered_dats"], ["Sony - PlayStation - BIOS Images"] ) + def test_a_loose_file_matches_by_crc32_and_size(self): + """Redump lists DTL-H10100's image by crc32 alone; collected as a + loose file it stayed MISSING for good.""" + db = {"files": {"f" * 40: {"name": "ps2-0101jd.bin", "size": 4194304, + "md5": "e" * 32, "crc32": "E9836A0C"}}} + snapshots = {"redump": {"source": "redump", "imported_at": "2026-10-09", + "dats": {"PS2 BIOS": "2026-10-01"}, + "entries": [{"name": "ps2-0101jd.bin", "size": 4194304, + "crc32": "e9836a0c", "md5": "", "sha1": "", + "dat": "PS2 BIOS"}]}} + report = build_report(db, snapshots) + self.assertEqual(report["redump"]["matched"], 1) + self.assertEqual(report["redump"]["missing"], []) + def test_uncovered_dat_entries_are_out_of_scope(self): """Entries from a DAT the collection never matches are not targets.