From a1dc6fa4efd2c3ab113ca7458bc4e0be9fb4680e Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Wed, 18 Mar 2026 06:52:07 +0100 Subject: [PATCH] fix: resolve_file prefers primary over variants for name fallback When resolving by name with no MD5 (existence check), prefer files NOT in .variants/ directory. Fixes naomi2.zip resolving to the Recalbox variant (15 files) instead of the primary (21 files). Also applies to hash_mismatch fallback path. --- scripts/generate_pack.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/generate_pack.py b/scripts/generate_pack.py index d46c0d9b..90950596 100644 --- a/scripts/generate_pack.py +++ b/scripts/generate_pack.py @@ -155,19 +155,27 @@ def resolve_file(file_entry: dict, db: dict, bios_dir: str, # No MD5 specified = any local file with that name is acceptable if not md5: name_matches = db.get("indexes", {}).get("by_name", {}).get(name, []) + candidates = [] for match_sha1 in name_matches: if match_sha1 in db["files"]: local_path = db["files"][match_sha1]["path"] if os.path.exists(local_path): - return local_path, "exact" + candidates.append(local_path) + if candidates: + primary = [p for p in candidates if "/.variants/" not in p] + return (primary[0] if primary else candidates[0]), "exact" - # Name fallback (hash mismatch) + # Name fallback (hash mismatch) - prefer primary over variants name_matches = db.get("indexes", {}).get("by_name", {}).get(name, []) + candidates = [] for match_sha1 in name_matches: if match_sha1 in db["files"]: local_path = db["files"][match_sha1]["path"] if os.path.exists(local_path): - return local_path, "hash_mismatch" + candidates.append(local_path) + if candidates: + primary = [p for p in candidates if "/.variants/" not in p] + return (primary[0] if primary else candidates[0]), "hash_mismatch" return None, "not_found"