fix: clone resolution in common.py, move clone map to root

moved _mame_clones.json out of bios/ (was indexed by generate_db.py
as BIOS file). clone resolution now in common.py resolve_local_file
so all tools (verify, pack, cross_reference) resolve clones
transparently. removed duplicate clone code from generate_pack.py.
added error handling on os.remove in dedup.py. consistency check
now passes for Batocera/EmuDeck/Lakka/RetroArch (4/6 platforms).
This commit is contained in:
Abdessamad Derraz
2026-03-24 21:57:49 +01:00
parent 85308edd73
commit ae4846550f
5 changed files with 39 additions and 55 deletions

View File

@@ -292,9 +292,38 @@ def resolve_local_file(
if os.path.exists(path):
return path, "zip_exact"
# MAME clone fallback: if a file was deduped, resolve via canonical
clone_map = _get_mame_clone_map()
canonical = clone_map.get(name)
if canonical and canonical != name:
canonical_entry = {"name": canonical}
result = resolve_local_file(canonical_entry, db, zip_contents, dest_hint)
if result[0]:
return result[0], "mame_clone"
return None, "not_found"
def _get_mame_clone_map() -> dict[str, str]:
"""Load and cache the MAME clone map (clone_name -> canonical_name)."""
if not hasattr(_get_mame_clone_map, "_cache"):
clone_path = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))),
"_mame_clones.json",
)
if os.path.exists(clone_path):
import json as _json
with open(clone_path) as f:
data = _json.load(f)
_get_mame_clone_map._cache = {}
for canonical, info in data.items():
for clone in info.get("clones", []):
_get_mame_clone_map._cache[clone] = canonical
else:
_get_mame_clone_map._cache = {}
return _get_mame_clone_map._cache
def check_inside_zip(container: str, file_name: str, expected_md5: str) -> str:
"""Check a ROM inside a ZIP — replicates Batocera checkInsideZip().