mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-11 12:33:53 -06:00
fix: keep the folder check's mode in DIGESTS
This commit is contained in:
1 parent
1bbbdcd4e4
commit
17e035ac8d
1 file changed
+4
-4
@@ -9,11 +9,12 @@ import zipfile
|
||||
from pathlib import Path
|
||||
|
||||
API = "https://abdess.github.io/retrobios/api/v1/platforms/"
|
||||
DIGESTS = {"md5": "md5", "sha1": "sha1"} # without one (existence), presence passes
|
||||
|
||||
|
||||
def accepts(entry: dict, path: Path, mode: str) -> bool:
|
||||
"""Whether the platform's own check passes the file at path."""
|
||||
digest, raw = mode if mode in ("md5", "sha1") else None, entry.get(mode) or "" # existence: no digest
|
||||
digest, raw = DIGESTS.get(mode), entry.get(mode) or ""
|
||||
values = [v.strip().lower() for v in (raw if isinstance(raw, list) else str(raw).split(",")) if v.strip()]
|
||||
if digest is None or not values:
|
||||
return path.is_file() # nothing to compare: the platform checks presence
|
||||
@@ -26,7 +27,7 @@ def accepts(entry: dict, path: Path, mode: str) -> bool:
|
||||
actual = hashlib.new(digest, path.read_bytes()).hexdigest()
|
||||
if entry.get("zip_digest") != "composite" and any(actual.startswith(v) for v in values):
|
||||
return True # a truncated md5 (Batocera) compares by its prefix
|
||||
if digest == "md5" and path.suffix.lower() == ".zip": # Recalbox: members in name order
|
||||
if digest == DIGESTS["md5"] and path.suffix.lower() == ".zip": # Recalbox: members in name order
|
||||
with zipfile.ZipFile(path) as archive:
|
||||
names = sorted(name for name in archive.namelist() if not name.endswith("/"))
|
||||
return hashlib.md5(b"".join(map(archive.read, names))).hexdigest() in values
|
||||
@@ -44,8 +45,7 @@ def check(platform: str, root: Path, api: str = API) -> list[tuple[str, str]]:
|
||||
listed = [e for e in system.get("files") or [] if not e.get("destination")]
|
||||
for entry in (e for e in system.get("files") or [] if e.get("destination")):
|
||||
path = root / entry["destination"]
|
||||
verdict = "ok" if accepts(entry, path, mode) else "wrong" if path.is_file() else "missing"
|
||||
results.append((entry["destination"], verdict))
|
||||
results.append((entry["destination"], "ok" if accepts(entry, path, mode) else "wrong" if path.is_file() else "missing"))
|
||||
if listed:
|
||||
held = any(accepts(e, path, mode) for e in listed for path in loose)
|
||||
results.append((f"{system_id}: any file", "ok" if held else "missing"))
|
||||
|
||||
Reference in new issue
Block a user