refactor: read archive members in one place

core.ziptools.zip_members lists the name, size and crc32 of each member once per archive revision. The site lookup and cards, the gap report, the pack check, the romset importer, the recipe identification and build, provenance, derivations and the atom pool read it instead of opening each archive again.

Each reader also tested a .zip suffix and skipped the .variants/ copies (x.zip.1a2b3c4d): the site lookup listed no member of a copy, the gap report's member index never saw one, the pack check never compared a copy's members, and the pack builders copied a copy without its CRC test. They now use is_archive_path. The inner ROM index of the resolver reads copies too, and a copy answers only for a member no primary holds.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 10:30:40 +01:00
1 parent 331f244aac
commit 74fcdd2bc5
16 files changed
+213 -103

No files matched your search

+13 -5
View File
@@ -14,6 +14,7 @@ from typing import TYPE_CHECKING, TypedDict
from core.hashing import parse_hash_list, stream_hashes
from core.paths import BIOS_DIR, PLATFORMS_DIR, REPO_ROOT
from core.ziptools import is_archive_path, zip_members
from model.alternatives import set_keys, set_requirements, settle_sets
from model.database import get_mame_clone_map, sha1_at
from model.profiles import lists_files
@@ -158,10 +159,14 @@ def _zip_members(bios_root: str | Path) -> list[tuple[str, list[str]]]:
return _zip_members_cache[key]
found: list[tuple[str, list[str]]] = []
root = Path(bios_root)
for zpath in root.rglob("*.zip") if root.is_dir() else ():
# .variants/ copies (x.zip.1a2b3c4d) are archives too.
archives = sorted(
p for p in (root.rglob("*") if root.is_dir() else ())
if is_archive_path(p.name) and p.is_file()
)
for zpath in archives:
try:
with zipfile.ZipFile(zpath) as zf:
members = [m for m in zf.namelist() if not m.endswith("/")]
members = [member.name for member in zip_members(zpath)]
except (zipfile.BadZipFile, OSError) as exc:
print(f" WARNING: unreadable archive {zpath}: {exc}", file=sys.stderr)
continue
@@ -345,10 +350,13 @@ def _content_matches(location: tuple[str, str], declared: dict[str, set[str]]) -
"""Whether the file or member at *location* carries a declared hash."""
path, member = location
try:
if member and set(declared) == {"crc32"}:
return any(
held.name == member and held.crc32 in declared["crc32"]
for held in zip_members(path)
)
if member:
with zipfile.ZipFile(path) as zf:
if set(declared) == {"crc32"}:
return f"{zf.getinfo(member).CRC:08x}" in declared["crc32"]
data = zf.read(member)
else:
data = Path(path).read_bytes()