refactor: read hashes and the registry one way

Hash fields go through core.hashing.parse_hash_list, which also splits comma-joined list items: the truth model compared a comma-joined sha256 list as one value. _registry.yml goes through load_platform_registry (required= where an absent file must stop the run), database.json through load_database, file and member digests through file_digest and stream_hashes. download.py and check_release read SHA256SUMS.txt with one parser: a sha256sum -b line matched nothing in download.py and the pack went unchecked.
This commit is contained in:
Abdessamad Derraz committed 2026-11-20 18:28:40 +01:00
1 parent 7cd499531d
commit 348d5b51c3
32 files changed
+130 -217

No files matched your search

+18 -2
View File
@@ -168,10 +168,11 @@ def parse_hash_list(raw: str | list | int | None) -> list[str]:
"""
if raw is None or raw == "":
return []
items = raw if isinstance(raw, list) else str(raw).split(",")
# A list item can itself be comma-joined (a list of Recalbox md5 fields).
items = [part for item in (raw if isinstance(raw, list) else [raw]) for part in str(item).split(",")]
out: list[str] = []
for item in items:
value = str(item).strip().lower().removeprefix("0x")
value = item.strip().lower().removeprefix("0x")
if value and value not in out:
out.append(value)
return out
@@ -184,3 +185,18 @@ def parse_md5_list(raw: str | list | None) -> list[str]:
emulator profiles carry a YAML list. Both reach here.
"""
return parse_hash_list(raw)
def parse_sha256sums(text: str) -> dict[str, str]:
"""`sha256sum` output by file name: digest, a space, then the mode
character (space for text, `*` for binary) before the name."""
sums: dict[str, str] = {}
for line in text.splitlines():
line = line.strip()
if not line:
continue
digest, _, name = line.partition(" ")
if len(digest) != 64 or not name:
raise ValueError(f"not a sha256sum line: {line!r}")
sums[name.lstrip(" *")] = digest.lower()
return sums