mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-30 05:18:51 -06:00
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:
1 parent
331f244aac
commit
74fcdd2bc5
16 files changed
+213
-103
No files matched your search
@@ -18,7 +18,7 @@ import zipfile
|
||||
from collections import defaultdict
|
||||
from collections.abc import Callable, Iterable, Sequence
|
||||
|
||||
from core.ziptools import is_archive_path
|
||||
from core.ziptools import is_archive_path, zip_members
|
||||
|
||||
# A held file larger than this is not read: no chip image is near it.
|
||||
MAX_SOURCE_SIZE = 64 * 1024 * 1024
|
||||
@@ -158,18 +158,17 @@ def _held_sources(db: dict) -> list[dict]:
|
||||
if not is_archive_path(path):
|
||||
continue
|
||||
try:
|
||||
with zipfile.ZipFile(path) as zf:
|
||||
infos = [i for i in zf.infolist() if not i.is_dir()]
|
||||
members = zip_members(path)
|
||||
except (OSError, zipfile.BadZipFile):
|
||||
continue
|
||||
sources.extend(
|
||||
{
|
||||
"path": f"{path}/{info.filename}", "archive": path,
|
||||
"member": info.filename, "size": info.file_size,
|
||||
"crc32": f"{info.CRC:08x}", "group": path,
|
||||
"path": f"{path}/{member.name}", "archive": path,
|
||||
"member": member.name, "size": member.size,
|
||||
"crc32": member.crc32, "group": path,
|
||||
}
|
||||
for info in infos
|
||||
if 0 < info.file_size <= MAX_SOURCE_SIZE
|
||||
for member in members
|
||||
if 0 < member.size <= MAX_SOURCE_SIZE
|
||||
)
|
||||
return sources
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ from pathlib import Path
|
||||
|
||||
from core.hashing import parse_hash_list
|
||||
from core.paths import REPO_ROOT
|
||||
from core.ziptools import is_archive_path
|
||||
from core.ziptools import is_archive_path, zip_members
|
||||
from resolve.content import size_fits
|
||||
|
||||
|
||||
@@ -136,12 +136,9 @@ def archive_members(db: dict) -> dict[tuple[str, int], list[tuple[str, str]]]:
|
||||
if not is_archive_path(path) or not os.path.exists(path):
|
||||
continue
|
||||
try:
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
for info in archive.infolist():
|
||||
if info.is_dir():
|
||||
continue
|
||||
key = (f"{info.CRC:08x}", info.file_size)
|
||||
members.setdefault(key, []).append((path, info.filename))
|
||||
for member in zip_members(path):
|
||||
key = (member.crc32, member.size)
|
||||
members.setdefault(key, []).append((path, member.name))
|
||||
except (zipfile.BadZipFile, OSError) as exc:
|
||||
print(f" WARNING: {path}: {exc}", file=sys.stderr)
|
||||
return members
|
||||
|
||||
Reference in new issue
Block a user