fix: arbitrate slots on the file the pack ships

This commit is contained in:
Abdessamad Derraz committed 2026-10-16 12:06:26 +02:00
1 parent 99c8974ecf
commit a8b9232093
4 files changed
+213 -92

No files matched your search

+1 -81
View File
@@ -55,7 +55,6 @@ from common import (
MANUFACTURER_PREFIXES,
parse_md5_list,
require_yaml,
resolution_is_hash_exact,
ProfileSelectionError,
resolve_local_file,
sanitize_pack_path,
@@ -435,86 +434,6 @@ def _report_pack_counts(
f"{core_count} from cores), {', '.join(parts)} [{verification_mode}]"
)
def _preferred_entries(
pack_systems: dict,
db: dict,
bios_dir: str,
base_dest: str,
required_only: bool,
zip_contents,
offline,
) -> dict[str, int]:
"""Which declaration wins when several claim the same destination.
A platform can declare one destination in more than one system, bare
in one and hash-constrained in another. First-come dedup would let
the bare entry pack whatever answers to the name, so a constrained
sibling that resolves by content claims the destination instead.
The choice is about the baseline and reads no data directory, for the
pack, the manifest and verify alike: verify alone passed the registry
and could crown a declaration only a data/ cache satisfies.
"""
preferred_entries: dict[str, int] = {}
dest_entries: dict[str, list[dict]] = {}
for sys_id, system in sorted(pack_systems.items()):
for file_entry in system.get("files", []):
if required_only and file_entry.get("required") is False:
continue
dest = sanitize_pack_path(
file_entry.get("destination", file_entry.get("name", ""))
)
if not dest:
continue
full = f"{base_dest}/{dest}" if base_dest else dest
dest_entries.setdefault(full, []).append(file_entry)
for full, entries in dest_entries.items():
if len(entries) < 2:
continue
constrained = [
fe
for fe in entries
if fe.get("md5") or fe.get("sha1") or fe.get("zipped_file")
]
if not constrained:
continue
resolved = [
(fe, *resolve_file(
fe,
db,
bios_dir,
zip_contents,
offline=offline,
))
for fe in constrained
]
members = [fe for fe in entries if fe.get("zipped_file")]
if members:
# One archive declared once per ROM it must hold: the archive
# to ship is the one the most declarations accept, not the first
# that answers one of them (adam_fdc.zip: a one-member MAME set
# answered first, the eight-member set sat beside it).
def accepted(path: str | None) -> int:
if not path or not path.endswith(".zip"):
return -1
return sum(inner_rom_check(fe, path) == "ok" for fe in members)
fe, path, _st = max(resolved, key=lambda item: accepted(item[1]))
if accepted(path) > 0:
preferred_entries[full] = id(fe)
continue
best = None
for fe, _lp, _st in resolved:
if _lp and _st == "md5_exact":
best = fe
break
if best is None and _lp and resolution_is_hash_exact(_st):
best = fe
if best is not None:
preferred_entries[full] = id(best)
return preferred_entries
def _select_variants(
config: dict,
pack_systems: dict,
@@ -4069,6 +3988,7 @@ from packverify import ( # noqa: E402,F401
# facade name would keep saying False after set_offline() changed the flag.
from packresolve import ( # noqa: E402,F401
_detect_hash_type,
preferred_entries as _preferred_entries,
parse_hash_input,
parse_hash_file,
lookup_hashes,