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

+4 -7
View File
@@ -9,6 +9,7 @@ from collections import defaultdict
from pathlib import Path
from core.torrentzip import is_torrentzip
from core.ziptools import zip_members
from romrecipes.pins import container_entries
from romrecipes.pool import AtomPool
from romrecipes.romsets import Recipe
@@ -39,11 +40,7 @@ def identify_archive(
def _member_list(path: Path) -> list[tuple[str, str]] | None:
"""Sorted (name, crc32) of an archive's members, from its directory."""
try:
with zipfile.ZipFile(path) as archive:
return sorted(
(info.filename, format(info.CRC, "08x"))
for info in archive.infolist() if not info.is_dir()
)
return sorted((member.name, member.crc32) for member in zip_members(path))
except (zipfile.BadZipFile, OSError) as exc:
print(f" UNREADABLE: {path}: {exc}", file=sys.stderr)
return None
@@ -84,10 +81,10 @@ def _is_archive(path: Path) -> bool:
ROM, not an archive. Recipes only describe archives.
"""
try:
with zipfile.ZipFile(path):
return True
zip_members(path)
except (OSError, zipfile.BadZipFile):
return False
return True
def _local_paths(archive: str, db: dict) -> list[Path]: