mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
refactor: read a declaration's slot one way
model.declarations.declared_slot(entry, prefix) is the declared destination less the platform's BIOS root, empty when the entry names no path. platform_declarations, platform_declared_contents, declared_destinations, system_core_reach, find_collisions and platform_claims read it in place of destination-or-name. The core extras of the builder and the manifest read declared_destination, and the builder's case twin list asks Placed.block. Behavior: the 134 EmuDeck system:md5 entries (destination: '') claim no slot. They were filed under their name, sony-playstation:<md5>, a path nothing else names: slots and collisions drop those claims, and case_folded_slots skips an empty slot. Their names and contents still count as declared, in the root folder as before.
This commit is contained in:
1 parent
c2dc50db50
commit
0095b23512
8 files changed
+36
-27
No files matched your search
@@ -5,7 +5,21 @@ from __future__ import annotations
|
||||
import os
|
||||
from collections import Counter
|
||||
|
||||
from core.paths import sanitize_pack_path
|
||||
from core.paths import declared_destination
|
||||
|
||||
|
||||
def declared_slot(entry: dict, prefix: str = "") -> str:
|
||||
"""The path a declaration claims, relative to the core file directory.
|
||||
|
||||
The declared destination (declared_destination), less the BIOS
|
||||
directory ``prefix`` the platform writes in front of it (declared_root).
|
||||
Empty when the declaration names no path, as EmuDeck's system:md5
|
||||
whitelist entries do: such a declaration claims no slot.
|
||||
"""
|
||||
slot = declared_destination(entry)
|
||||
if prefix and slot.lower().startswith(prefix.lower() + "/"):
|
||||
slot = slot[len(prefix) + 1:]
|
||||
return slot
|
||||
|
||||
|
||||
def platform_declarations(
|
||||
@@ -34,9 +48,8 @@ def platform_declarations(
|
||||
for system in config.get("systems", {}).values():
|
||||
for fe in system.get("files", []):
|
||||
name = fe.get("name", "")
|
||||
slot = sanitize_pack_path(fe.get("destination") or name).lower()
|
||||
if prefix and slot.startswith(prefix + "/"):
|
||||
slot = slot[len(prefix) + 1:]
|
||||
# An entry without a path still declares its name and content.
|
||||
slot = declared_slot(fe, prefix).lower()
|
||||
# A zipped_file entry pins a member of the archive it names: its
|
||||
# md5 and its size, when stated, are not the archive's.
|
||||
by_hash: dict = {}
|
||||
@@ -110,10 +123,7 @@ def platform_declared_contents(config: dict, db: dict) -> dict[str, set[str]]:
|
||||
record = files_db.get(sha1[0] if isinstance(sha1, list) else sha1)
|
||||
if not record:
|
||||
continue
|
||||
slot = sanitize_pack_path(fe.get("destination") or fe.get("name", "")).lower()
|
||||
if prefix and slot.startswith(prefix + "/"):
|
||||
slot = slot[len(prefix) + 1:]
|
||||
folder = slot.rpartition("/")[0]
|
||||
folder = declared_slot(fe, prefix).lower().rpartition("/")[0]
|
||||
for field in ("md5", "sha1", "crc32"):
|
||||
value = str(record.get(field) or "").lower()
|
||||
if value:
|
||||
|
||||
@@ -7,7 +7,7 @@ from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, TypedDict
|
||||
|
||||
from core.options import reject_unknown
|
||||
from core.paths import sanitize_pack_path
|
||||
from core.paths import declared_destination
|
||||
from model.alternatives import core_file_spares
|
||||
from model.declarations import OUTER_ROOTS, ROMS_ROOT, declared_root
|
||||
from model.profiles import upstream_profile_index
|
||||
@@ -93,7 +93,7 @@ class _CoreEntryLister:
|
||||
|
||||
def list_extra(self, fe: dict) -> None:
|
||||
state = self.state
|
||||
dest = sanitize_pack_path(fe.get("destination", fe["name"]))
|
||||
dest = declared_destination(fe)
|
||||
if not dest:
|
||||
return
|
||||
region_key = self.region_key(fe)
|
||||
|
||||
@@ -14,7 +14,7 @@ from typing import TYPE_CHECKING, TypedDict
|
||||
from model.registry import load_platform_registry
|
||||
from core.hashing import compute_hashes
|
||||
from core.options import reject_unknown
|
||||
from core.paths import EMULATORS_DIR, sanitize_pack_path
|
||||
from core.paths import EMULATORS_DIR, declared_destination, sanitize_pack_path
|
||||
from model.alternatives import core_file_spares
|
||||
from model.declarations import OUTER_ROOTS, declared_root
|
||||
from model.platforms import load_platform_config
|
||||
@@ -833,7 +833,7 @@ class _PlatformPackBuild:
|
||||
|
||||
def _pack_core_file(self, fe: dict) -> None:
|
||||
plan = self.plan
|
||||
dest = sanitize_pack_path(fe.get("destination", fe["name"]))
|
||||
dest = declared_destination(fe)
|
||||
if self._region_dropped(fe):
|
||||
return
|
||||
if not dest:
|
||||
@@ -985,10 +985,8 @@ class _PlatformPackBuild:
|
||||
continue
|
||||
full = extra_full_destination(fe, prefix)
|
||||
if (
|
||||
full and full not in self.placed.destinations and full.lower() in self.placed.lower
|
||||
and self.resolve_extra(
|
||||
fe, sanitize_pack_path(fe.get("destination", fe["name"]))
|
||||
)[0]
|
||||
full and self.placed.block(full) == "case_twin"
|
||||
and self.resolve_extra(fe, declared_destination(fe))[0]
|
||||
):
|
||||
self.case_twins.append(self._flat(full))
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from core.hashing import parse_md5_list
|
||||
from model.declarations import declared_slot
|
||||
from model.profiles import entry_system_ids, lists_files
|
||||
from resolve import nativemode
|
||||
from resolve.archives import archive_entry, holds_required_members
|
||||
@@ -116,7 +117,7 @@ def platform_claims(
|
||||
for entry in system.get("files") or []:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
dest = entry.get("destination") or entry.get("name") or ""
|
||||
dest = declared_slot(entry)
|
||||
if not dest:
|
||||
continue
|
||||
full = f"{base_dest}/{dest}" if base_dest else dest
|
||||
|
||||
@@ -11,6 +11,7 @@ from core.paths import comparable_destination
|
||||
from core.ziptools import check_inside_zip
|
||||
from resolve.localfile import resolve_local_file, variant_base_name
|
||||
from model.database import record_at
|
||||
from model.declarations import declared_slot
|
||||
from resolve.packfiles import preferred_entries
|
||||
|
||||
|
||||
@@ -57,7 +58,7 @@ def find_collisions(
|
||||
for entry in system.get("files") or []:
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
dest = entry.get("destination") or entry.get("name") or ""
|
||||
dest = declared_slot(entry)
|
||||
if dest:
|
||||
by_dest.setdefault(comparable_destination(dest, fold), []).append((sys_id, entry))
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ from collections.abc import Collection
|
||||
|
||||
from core.cli import suggest_names
|
||||
from core.paths import sanitize_pack_path
|
||||
from model.declarations import declared_slot
|
||||
from model.platforms import load_platform_config
|
||||
from model.profiles import preferred_profile, upstream_profile_index
|
||||
from model.systems import norm_system_id, select_systems
|
||||
@@ -348,10 +349,8 @@ def system_core_reach(
|
||||
file_cores = {
|
||||
core
|
||||
for fe in sys_data.get("files", [])
|
||||
for core in dest_cores.get(
|
||||
sanitize_pack_path(fe.get("destination") or fe.get("name", "")).lower(),
|
||||
(),
|
||||
)
|
||||
if (slot := declared_slot(fe))
|
||||
for core in dest_cores.get(slot.lower(), ())
|
||||
}
|
||||
reach[sys_id] = file_cores | norm_system_cores.get(norm_key, set())
|
||||
return reach
|
||||
|
||||
@@ -22,7 +22,7 @@ from dataclasses import dataclass
|
||||
|
||||
from core.hashing import parse_hash_list
|
||||
from model.database import record_at
|
||||
from model.declarations import CONFIGS_ROOT, ROMS_ROOT, declared_root, outer_layout
|
||||
from model.declarations import CONFIGS_ROOT, ROMS_ROOT, declared_root, declared_slot, outer_layout
|
||||
from model.profiles import lists_files
|
||||
from resolve.content import name_match_size_ok
|
||||
from resolve.localfile import resolve_local_file
|
||||
@@ -1253,9 +1253,7 @@ def declared_destinations(config: dict) -> set[str]:
|
||||
found: set[str] = set()
|
||||
for system in config.get("systems", {}).values():
|
||||
for entry in system.get("files", []):
|
||||
slot = sanitize_pack_path(entry.get("destination") or entry.get("name", ""))
|
||||
if prefix and slot.lower().startswith(prefix.lower() + "/"):
|
||||
slot = slot[len(prefix) + 1:]
|
||||
slot = declared_slot(entry, prefix)
|
||||
if slot:
|
||||
found.add(slot)
|
||||
return found
|
||||
|
||||
@@ -691,7 +691,9 @@ def case_folded_slots(
|
||||
"""
|
||||
if not config.get("case_insensitive_fs", False):
|
||||
return frozenset()
|
||||
return frozenset(where for places in declarations.values() for _size, where in places)
|
||||
return frozenset(
|
||||
where for places in declarations.values() for _size, where in places if where
|
||||
)
|
||||
|
||||
|
||||
def declaration_settles(
|
||||
|
||||
Reference in new issue
Block a user