mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 02:27:52 -06:00
refactor: read zip member crcs in one place
core.ziptools.readable_zip_member_crcs answers None for a file that is no readable archive, and zip_member_crcs reads it as empty. The covering archive choice of resolve.packfiles uses it in place of its own reader, so it still gives up on an unreadable candidate and now shares the cache. No behavior change.
This commit is contained in:
1 parent
187d9ea5e4
commit
cc85999e22
2 files changed
+14
-17
No files matched your search
@@ -69,14 +69,14 @@ def _member_md5(
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=4096)
|
||||
def _member_crcs(path: str, mtime: float) -> frozenset[str]:
|
||||
def _member_crcs(path: str, mtime: float) -> frozenset[str] | None:
|
||||
try:
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
return frozenset(
|
||||
format(info.CRC, "08x") for info in archive.infolist() if not info.is_dir()
|
||||
)
|
||||
except (zipfile.BadZipFile, OSError):
|
||||
return frozenset()
|
||||
return None
|
||||
|
||||
|
||||
@functools.lru_cache(maxsize=4096)
|
||||
@@ -100,15 +100,21 @@ def zip_member_names(path: str) -> frozenset[str]:
|
||||
return _member_names(path, mtime)
|
||||
|
||||
|
||||
def zip_member_crcs(path: str) -> frozenset[str]:
|
||||
"""CRC-32 of each member, read from the central directory."""
|
||||
def readable_zip_member_crcs(path: str) -> frozenset[str] | None:
|
||||
"""CRC-32 of each member, read from the central directory, None when
|
||||
the file is no readable archive."""
|
||||
try:
|
||||
mtime = os.path.getmtime(path)
|
||||
except OSError:
|
||||
return frozenset()
|
||||
return None
|
||||
return _member_crcs(path, mtime)
|
||||
|
||||
|
||||
def zip_member_crcs(path: str) -> frozenset[str]:
|
||||
"""CRC-32 of each member, empty when the file is no readable archive."""
|
||||
return readable_zip_member_crcs(path) or frozenset()
|
||||
|
||||
|
||||
_zip_contents_cache: tuple[tuple, dict] | None = None
|
||||
|
||||
# Member md5s per archive, keyed by the archive's sha1: content addressed, so
|
||||
|
||||
Reference in new issue
Block a user