diff --git a/scripts/exporter/baseline.py b/scripts/exporter/baseline.py index 5fde02a5..0ca0218d 100644 --- a/scripts/exporter/baseline.py +++ b/scripts/exporter/baseline.py @@ -153,9 +153,15 @@ class NativeFile: truth's size is only taken when the truth also speaks for the hash: a name-matched 480-byte fbneo boot.bin turned RomM's Dreamcast boot.bin into size 480 beside its 2 MB md5, which never verifies. + When the truth contradicts the platform's hash, the platform's size + describes the dump the truth rejects: geolith's neocdz.zip md5 went + out beside System.dat's 953078 bytes, a record no file satisfies. """ source = self._identity_source() - order = (self.platform, self.truth) if source == "platform" else (self.truth, self.platform) + order = { + "platform": (self.platform, self.truth), + "truth": (self.truth,), + }.get(source, (self.truth, self.platform)) for entry in order: if entry and entry.get("size"): return _single_size(entry["size"]) diff --git a/tests/test_exporters.py b/tests/test_exporters.py index 10280f1b..897eedff 100644 --- a/tests/test_exporters.py +++ b/tests/test_exporters.py @@ -136,6 +136,21 @@ class Reconciliation(unittest.TestCase): self.assertIsNone(platform_entry.truth) self.assertEqual(report.hashes_corrected, []) + def test_a_contradicted_hash_takes_no_platform_size(self): + """geolith's neocdz.zip md5 contradicts System.dat's: the export + wrote that md5 beside System.dat's 953078 bytes.""" + entry = NativeFile( + "neocdz.zip", "neocdz.zip", "neocd", + platform={"md5": "a" * 32, "size": 953078}, + truth={"md5": "b" * 32}, + ) + self.assertEqual((entry.hash("md5"), entry.size()), ("b" * 32, None)) + agreeing = NativeFile( + "neocdz.zip", "neocdz.zip", "neocd", + platform={"md5": "b" * 32, "size": 955352}, truth={"md5": "b" * 32}, + ) + self.assertEqual(agreeing.size(), 955352) + def test_a_file_the_truth_says_nothing_about_is_kept(self): systems, _ = model() names = {fe.name for fe in systems["psx"].files}