mirror of
https://github.com/Abdess/retrobios.git
synced 2026-06-30 06:12:47 +00:00
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.
This commit is contained in:
parent
b0dad7dcf3
commit
a1dc6fa4ef
1 changed files with 11 additions and 3 deletions
|
|
@ -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
|
# No MD5 specified = any local file with that name is acceptable
|
||||||
if not md5:
|
if not md5:
|
||||||
name_matches = db.get("indexes", {}).get("by_name", {}).get(name, [])
|
name_matches = db.get("indexes", {}).get("by_name", {}).get(name, [])
|
||||||
|
candidates = []
|
||||||
for match_sha1 in name_matches:
|
for match_sha1 in name_matches:
|
||||||
if match_sha1 in db["files"]:
|
if match_sha1 in db["files"]:
|
||||||
local_path = db["files"][match_sha1]["path"]
|
local_path = db["files"][match_sha1]["path"]
|
||||||
if os.path.exists(local_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, [])
|
name_matches = db.get("indexes", {}).get("by_name", {}).get(name, [])
|
||||||
|
candidates = []
|
||||||
for match_sha1 in name_matches:
|
for match_sha1 in name_matches:
|
||||||
if match_sha1 in db["files"]:
|
if match_sha1 in db["files"]:
|
||||||
local_path = db["files"][match_sha1]["path"]
|
local_path = db["files"][match_sha1]["path"]
|
||||||
if os.path.exists(local_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"
|
return None, "not_found"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue