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
@@ -12,7 +12,7 @@ from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
from core.artifacts import build_timestamp
|
||||
from packs.paths import MEDIA_MARKER, has_path_conflict
|
||||
from core.ziptools import build_zip_contents_index, is_archive_path
|
||||
from core.ziptools import build_zip_contents_index, is_archive_path, zip_members
|
||||
from core.ziptools import safe_member_parts
|
||||
from resolve.nativemode import digest_algorithm, platform_mode
|
||||
from resolve.validation import (
|
||||
@@ -106,10 +106,6 @@ def _settle_untracked(
|
||||
return "untracked", file_name
|
||||
|
||||
|
||||
def _member_crcs(archive: zipfile.ZipFile) -> dict[str, int]:
|
||||
return {i.filename: i.CRC for i in archive.infolist() if not i.is_dir()}
|
||||
|
||||
|
||||
def _same_members(pack: zipfile.ZipFile, name: str, source: str) -> bool:
|
||||
"""Whether a ZIP inside the pack holds the members of a ZIP on disk.
|
||||
|
||||
@@ -118,9 +114,12 @@ def _same_members(pack: zipfile.ZipFile, name: str, source: str) -> bool:
|
||||
each carried their own copy.
|
||||
"""
|
||||
try:
|
||||
with zipfile.ZipFile(io.BytesIO(pack.read(name))) as packed, \
|
||||
zipfile.ZipFile(source) as held:
|
||||
return _member_crcs(packed) == _member_crcs(held)
|
||||
held = {member.name: member.crc32 for member in zip_members(source)}
|
||||
with zipfile.ZipFile(io.BytesIO(pack.read(name))) as packed:
|
||||
return held == {
|
||||
info.filename: format(info.CRC, "08x")
|
||||
for info in packed.infolist() if not info.is_dir()
|
||||
}
|
||||
except (zipfile.BadZipFile, OSError):
|
||||
return False
|
||||
|
||||
@@ -622,7 +621,7 @@ def _same_content(zf: zipfile.ZipFile, member: str, local: str) -> bool:
|
||||
with open(local, "rb") as handle:
|
||||
if zf.read(member) == handle.read():
|
||||
return True
|
||||
return local.lower().endswith(".zip") and _same_members(zf, member, local)
|
||||
return is_archive_path(local) and _same_members(zf, member, local)
|
||||
|
||||
|
||||
class PlatformCheckOptions(TypedDict, total=False):
|
||||
|
||||
Reference in new issue
Block a user