mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-25 10:58:52 -06:00
refactor: read declared hashes with one helper
core.hashing.declared_hash_lists gives an entry's declared values per field in the order written, and declared_hashes builds its sets on it. The gap page, the doubled-destination report and the file lookup used their own copies of that reader. The wanted page keeps its filters on top of it. sitegen.lookup.hash_pairs replaces sorted_hash_values for the lookup, the data exports and the structured data. The one-field aliases parse_md5_list and reconcile.hash_values are gone, and model.profiles reads HASH_FIELDS instead of a fourth tuple.
This commit is contained in:
1 parent
ea68e85c06
commit
02969dda06
30 files changed
+176
-195
No files matched your search
@@ -18,9 +18,9 @@ from pathlib import Path
|
||||
|
||||
from model.systems import norm_system_id
|
||||
from resolve.cores import resolve_platform_cores, unresolved_platform_cores
|
||||
from core.hashing import declared_hashes
|
||||
from core.hashing import declared_hashes, parse_hash_list
|
||||
from resolve.reconcile import (
|
||||
HASH_FIELDS, NativeSystem, comparable, contradicts, entry_names, hash_values,
|
||||
HASH_FIELDS, NativeSystem, comparable, contradicts, entry_names,
|
||||
)
|
||||
from resolve.launchers import record_names as launcher_names
|
||||
|
||||
@@ -32,10 +32,10 @@ def _tails(path: str) -> list[str]:
|
||||
|
||||
|
||||
def _entry_hashes(entry: dict) -> set[str]:
|
||||
values = {v for f in HASH_FIELDS for v in hash_values(entry, f)}
|
||||
values = {v for f in HASH_FIELDS for v in parse_hash_list(entry.get(f))}
|
||||
for member in entry.get("contents") or []:
|
||||
if isinstance(member, dict):
|
||||
values |= {v for f in HASH_FIELDS for v in hash_values(member, f)}
|
||||
values |= {v for f in HASH_FIELDS for v in parse_hash_list(member.get(f))}
|
||||
return values
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ def _declared_hashes(entry: dict) -> dict[str, set[str]]:
|
||||
"""
|
||||
entry = comparable(entry)
|
||||
found = declared_hashes(entry)
|
||||
if alt := set(hash_values(entry, "alt_md5")):
|
||||
if alt := set(parse_hash_list(entry.get("alt_md5"))):
|
||||
found["md5"] = found.get("md5", set()) | alt
|
||||
return found
|
||||
|
||||
@@ -129,7 +129,7 @@ class ReadEvidence:
|
||||
if names & self.names or (tails and tails[-1] in self.names):
|
||||
return "name"
|
||||
hashes = {
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in hash_values(entry, f)
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in parse_hash_list(entry.get(f))
|
||||
}
|
||||
if hashes & self.hashes:
|
||||
return "hash"
|
||||
@@ -183,7 +183,7 @@ class ProofIndex:
|
||||
tails = _tails(destination)
|
||||
last = {tails[-1]} if tails else set()
|
||||
hashes = {
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in hash_values(entry, f)
|
||||
v for f in (*HASH_FIELDS, "alt_md5") for v in parse_hash_list(entry.get(f))
|
||||
}
|
||||
# "/" + d in "/" + path: d is a run of whole segments ending in "/",
|
||||
# so it is a run of the path's segments before the last one.
|
||||
|
||||
@@ -6,7 +6,7 @@ import os
|
||||
import zlib
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from core.hashing import compute_hashes, declared_hashes, parse_md5_list
|
||||
from core.hashing import compute_hashes, declared_hashes, parse_hash_list
|
||||
from core.paths import comparable_destination
|
||||
from core.ziptools import check_inside_zip
|
||||
from resolve.localfile import resolve_local_file, variant_base_name
|
||||
@@ -126,7 +126,7 @@ def accepted_by_all(path: str, entries: list[dict], db: dict) -> bool:
|
||||
return False
|
||||
for entry in entries:
|
||||
if entry.get("zipped_file"):
|
||||
declared = parse_md5_list(entry.get("md5"))
|
||||
declared = parse_hash_list(entry.get("md5"))
|
||||
if declared and not any(
|
||||
check_inside_zip(path, entry["zipped_file"], m) == "ok" for m in declared
|
||||
):
|
||||
|
||||
@@ -10,7 +10,7 @@ from collections.abc import Iterator
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
from core.hashing import cut_md5_owner, md5_composite, parse_md5_list
|
||||
from core.hashing import cut_md5_owner, md5_composite, parse_hash_list
|
||||
from core.memo import DerivedView
|
||||
from core.ziptools import check_inside_zip
|
||||
from model.database import get_mame_clone_map
|
||||
@@ -339,7 +339,7 @@ def held_record_for(file_entry: dict, db: dict) -> str | None:
|
||||
by_md5 = indexes.get("by_md5", {})
|
||||
md5_list = [
|
||||
(cut_md5_owner(value, by_md5) or value) if len(value) < 32 else value
|
||||
for value in parse_md5_list(file_entry.get("md5"))
|
||||
for value in parse_hash_list(file_entry.get("md5"))
|
||||
]
|
||||
q = _lookup(
|
||||
file_entry, db, "", md5_list,
|
||||
@@ -1026,7 +1026,7 @@ def resolve_local_file(
|
||||
file_entry, db, zip_contents, dest_hint,
|
||||
depth=_depth, data_dir_registry=data_dir_registry,
|
||||
)
|
||||
md5_list = parse_md5_list(file_entry.get("md5"))
|
||||
md5_list = parse_hash_list(file_entry.get("md5"))
|
||||
by_md5 = db.get("indexes", {}).get("by_md5", {})
|
||||
# A value cut short stands for the one held md5 it starts, and only
|
||||
# then (cut_md5_owner): the dump it names is still name-guarded below.
|
||||
|
||||
@@ -23,11 +23,6 @@ from model.systems import norm_system_id
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
def hash_values(entry: dict, field_name: str) -> list[str]:
|
||||
"""Return a hash field as a list, whatever shape it was written in."""
|
||||
return parse_hash_list(entry.get(field_name))
|
||||
|
||||
|
||||
def checked_hashes(entry: dict | None) -> dict | None:
|
||||
"""The truth entry with only the hashes its code checks.
|
||||
|
||||
@@ -57,8 +52,8 @@ def checked_hashes(entry: dict | None) -> dict | None:
|
||||
kinds = {str(k) for k in raw}
|
||||
else:
|
||||
kinds = {str(raw)}
|
||||
checked = [f for f in HASH_FIELDS if f in kinds and hash_values(entry, f)]
|
||||
if checked and all(len(set(hash_values(entry, f))) == 1 for f in checked):
|
||||
checked = [f for f in HASH_FIELDS if f in kinds and parse_hash_list(entry.get(f))]
|
||||
if checked and all(len(set(parse_hash_list(entry.get(f)))) == 1 for f in checked):
|
||||
return entry
|
||||
return {k: v for k, v in entry.items() if k not in HASH_FIELDS or k in kinds}
|
||||
|
||||
@@ -116,7 +111,7 @@ def is_placeholder(name: str) -> bool:
|
||||
|
||||
|
||||
def _field_sets(entry: dict | None) -> dict[str, set[str]]:
|
||||
return {f: set(hash_values(entry or {}, f)) for f in HASH_FIELDS}
|
||||
return {f: set(parse_hash_list((entry or {}).get(f))) for f in HASH_FIELDS}
|
||||
|
||||
|
||||
def single_size(value: int | str | list[int | str]) -> int | None:
|
||||
@@ -206,9 +201,9 @@ class NativeFile:
|
||||
rejects a file will reject it whatever the platform declares.
|
||||
"""
|
||||
if field_name == "md5" and self.composite_md5:
|
||||
return hash_values(self.platform or {}, field_name)
|
||||
truth_values = hash_values(self._checked_truth, field_name)
|
||||
platform_values = hash_values(self.platform or {}, field_name)
|
||||
return parse_hash_list((self.platform or {}).get(field_name))
|
||||
truth_values = parse_hash_list(self._checked_truth.get(field_name))
|
||||
platform_values = parse_hash_list((self.platform or {}).get(field_name))
|
||||
source = self._identity_source()
|
||||
if source == "platform":
|
||||
return platform_values
|
||||
@@ -242,11 +237,11 @@ class NativeFile:
|
||||
is written when it names one value, which is then that dump's.
|
||||
"""
|
||||
if field_name == "md5" and self.composite_md5:
|
||||
values = hash_values(self.platform or {}, field_name)
|
||||
values = parse_hash_list((self.platform or {}).get(field_name))
|
||||
return values[0] if values else ""
|
||||
source = self._identity_source()
|
||||
truth_values = hash_values(self._checked_truth, field_name)
|
||||
platform_values = hash_values(self.platform or {}, field_name)
|
||||
truth_values = parse_hash_list(self._checked_truth.get(field_name))
|
||||
platform_values = parse_hash_list((self.platform or {}).get(field_name))
|
||||
if source == "truth":
|
||||
return truth_values[0] if truth_values else ""
|
||||
if source == "platform" or not truth_values:
|
||||
@@ -531,8 +526,8 @@ def _correct_matched(matched: NativeFile, truth_entry: dict, report: Report) ->
|
||||
report.hashes_corrected.append(
|
||||
f"{matched.native_system}/{matched.name} {field_name}"
|
||||
)
|
||||
elif hash_values(checked, field_name) and not hash_values(
|
||||
comparable(matched.platform), field_name
|
||||
elif parse_hash_list(checked.get(field_name)) and not parse_hash_list(
|
||||
comparable(matched.platform).get(field_name)
|
||||
):
|
||||
matched.filled.append(field_name)
|
||||
t_req = truth_entry.get("required")
|
||||
|
||||
@@ -15,7 +15,7 @@ try:
|
||||
except ImportError:
|
||||
yaml = None
|
||||
|
||||
from core.hashing import compute_hashes, parse_hash_list, parse_md5_list, stream_hashes
|
||||
from core.hashing import compute_hashes, parse_hash_list, stream_hashes
|
||||
from model.nodedup import in_nodedup_dir
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import load_emulator_profiles
|
||||
@@ -179,7 +179,7 @@ def load_platform_hashes(platforms_dir: str, db: dict | None = None) -> dict:
|
||||
for system_id, system in config.get("systems", {}).items():
|
||||
for file_entry in system.get("files", []):
|
||||
sha1s = parse_hash_list(file_entry.get("sha1"))
|
||||
md5s = parse_md5_list(file_entry.get("md5"))
|
||||
md5s = parse_hash_list(file_entry.get("md5"))
|
||||
sha256s = parse_hash_list(file_entry.get("sha256"))
|
||||
known["sha1"].update(sha1s)
|
||||
known["md5"].update(md5s)
|
||||
|
||||
@@ -26,7 +26,7 @@ from resolve.archives import archive_members
|
||||
from model.profiles import CONTENT_CHECKS, entry_system_ids, lists_files
|
||||
from core.hashing import compute_hashes, parse_hash_list
|
||||
from core.paths import BIOS_DIR, sanitize_pack_path
|
||||
from core.hashing import lists_hashes, md5_composite, parse_md5_list
|
||||
from core.hashing import lists_hashes, md5_composite
|
||||
from resolve.nativemode import SIZE_AND_ANY_HASH, digest_algorithm, hash_mismatch_excludes_file
|
||||
from core.ziptools import check_inside_zip, check_inside_zip_data
|
||||
|
||||
@@ -791,7 +791,7 @@ def _platform_accepted(file_entry: dict, platform_digest: str) -> set[str]:
|
||||
"""The values of the digest the frontend compares that the entry declares."""
|
||||
declared = file_entry.get(platform_digest) or ""
|
||||
if platform_digest == "md5":
|
||||
return set(parse_md5_list(declared))
|
||||
return set(parse_hash_list(declared))
|
||||
if isinstance(declared, str) and declared:
|
||||
return {declared.lower()}
|
||||
if isinstance(declared, list):
|
||||
@@ -964,7 +964,7 @@ def digest_verdict(
|
||||
if file_entry.get(field)
|
||||
)
|
||||
if algorithm == "md5":
|
||||
declared = parse_md5_list(file_entry.get("md5"))
|
||||
declared = parse_hash_list(file_entry.get("md5"))
|
||||
else:
|
||||
value = file_entry.get(algorithm)
|
||||
values = value if isinstance(value, list) else [value]
|
||||
@@ -1011,7 +1011,7 @@ def inner_rom_data_check(file_entry: dict, data: bytes) -> str:
|
||||
def _first_accepted_md5(file_entry: dict, check: Callable[[str], str]) -> str:
|
||||
# With no md5 declared, checkInsideZip still runs and needs the member.
|
||||
result = "not_in_zip"
|
||||
for candidate in parse_md5_list(file_entry.get("md5")) or [""]:
|
||||
for candidate in parse_hash_list(file_entry.get("md5")) or [""]:
|
||||
result = check(candidate)
|
||||
if result == "ok":
|
||||
break
|
||||
|
||||
Reference in new issue
Block a user