From e644463c17b83983b0f0d110115ed9420b93cc41 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sun, 18 Oct 2026 19:40:25 +0200 Subject: [PATCH] fix: read the data directory before other casings Widening the name step to every casing served blueMSX a different MSX2P.ROM dump while data/bluemsx held the one it ships. --- scripts/common.py | 13 ++++++++++--- tests/test_foreign_tree_names.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/scripts/common.py b/scripts/common.py index f798481b..72c874d4 100644 --- a/scripts/common.py +++ b/scripts/common.py @@ -1365,7 +1365,12 @@ def resolve_local_file( ): candidates.append(path) owners = _owner_tokens(file_entry) - if not candidates or all(_foreign_tree(p, owners) for p in candidates): + # Only another emulator's tree answers the exact casing: what it + # holds there says nothing about this entry's file. + exact_foreign = bool(candidates) and all( + _foreign_tree(p, owners) for p in candidates + ) + if not candidates or exact_foreign: # Case-insensitive fallback: upstream platforms disagree on # casing (VEC_MineStorm.vec vs VEC_Minestorm.vec). Two casings # can name two contents (FONT.ROM and font.rom), so this only @@ -1403,8 +1408,10 @@ def resolve_local_file( # and a data directory it reads may hold it. Dolphin got # Dolphin-MMJR's codehandler.bin while data/dolphin-sys held # its own; blueMSX got the 16 KB RS232.ROM once msx-emu's - # 8 KB copy was set aside, while data/bluemsx held its own. - if data_dir_registry and _foreign_tree(best, owners): + # 8 KB copy was set aside, while data/bluemsx held its own, + # and MSX2P.ROM of another dump once only msx-emu answered + # the exact casing. + if data_dir_registry and (exact_foreign or _foreign_tree(best, owners)): hit, _mismatch = _resolve_in_data_dirs( names_to_try, data_dir_registry, functools.partial( diff --git a/tests/test_foreign_tree_names.py b/tests/test_foreign_tree_names.py index a4aea6f5..2a24e878 100644 --- a/tests/test_foreign_tree_names.py +++ b/tests/test_foreign_tree_names.py @@ -73,6 +73,26 @@ class ForeignTreeNames(unittest.TestCase): self.assertEqual(status, "data_dir") self.assertEqual(Path(path).stat().st_size, 64) + def test_a_casing_only_another_tree_holds_reads_the_data_directory(self): + """MSX2P.rom: only msx-emu's tree had the exact casing, and widening + to every casing served Microsoft/MSX/MSX2P.ROM, another dump, while + data/bluemsx held the one blueMSX ships.""" + self._hold("bios/Other/msx-emu/Machines/Shared Roms/MSX2P.rom", b"B" * 64) + self._hold("bios/Microsoft/MSX/MSX2P.ROM", b"O" * 64) + cache = self.root / "data" / "bluemsx" + (cache / "Machines" / "Shared Roms").mkdir(parents=True) + (cache / "Machines" / "Shared Roms" / "MSX2P.rom").write_bytes(b"B" * 64) + entry = { + "name": "MSX2P.rom", "path": "Machines/Shared Roms/MSX2P.rom", + "source_emulator": "bluemsx", + } + path, status = resolve_local_file( + entry, self.db, + data_dir_registry={"bluemsx": {"local_cache": str(cache)}}, + ) + self.assertEqual(status, "data_dir") + self.assertEqual(Path(path).read_bytes(), b"B" * 64) + if __name__ == "__main__": unittest.main()