mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-24 02:27:52 -06:00
refactor: fold destinations with one rule
comparable_destination moves to core.paths. Placed, placement_block, the shared group merge of model.platforms and LauncherPlace.fold read it in place of their own lower(). It also trims surrounding blanks and slashes and folds with casefold: no destination, collection path or launcher name differs under those rules today, so the output is the same.
This commit is contained in:
1 parent
ca3ff1d4c5
commit
1c978f3083
7 files changed
+27
-23
No files matched your search
@@ -28,6 +28,16 @@ def sanitize_pack_path(raw: str) -> str:
|
||||
return "/".join(p for p in raw.split("/") if p and p not in ("..", "."))
|
||||
|
||||
|
||||
def comparable_destination(destination: str, fold: bool = True) -> str:
|
||||
"""Comparable form of a destination, since layers write it differently.
|
||||
|
||||
Case is folded only where the platform's filesystem folds it: on Linux
|
||||
RetroDECK ships bios/DISK.ROM and bios/disk.rom side by side.
|
||||
"""
|
||||
cleaned = destination.strip().strip("/").replace("\\", "/")
|
||||
return cleaned.casefold() if fold else cleaned
|
||||
|
||||
|
||||
def declared_destination(entry: dict) -> str:
|
||||
"""The destination a declaration names, its name when it names none,
|
||||
normalized as sanitize_pack_path does: the key the builder, the manifest
|
||||
|
||||
@@ -9,7 +9,7 @@ try:
|
||||
except ImportError:
|
||||
yaml = None
|
||||
|
||||
from core.paths import PLATFORMS_DIR
|
||||
from core.paths import PLATFORMS_DIR, comparable_destination
|
||||
from model.sources import source_yaml
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ def _apply_shared_groups(config: dict, shared_groups: dict) -> None:
|
||||
# Lakka and RetroPie run on Linux, and np2kai opens 2608_bd.wav beside
|
||||
# System.dat's 2608_BD.WAV.
|
||||
def fold(destination: str) -> str:
|
||||
return destination.lower() if config.get("case_insensitive_fs") else destination
|
||||
return comparable_destination(destination, bool(config.get("case_insensitive_fs")))
|
||||
|
||||
for system in config.get("systems", {}).values():
|
||||
for group_name in system.get("includes", []):
|
||||
|
||||
@@ -14,7 +14,7 @@ from pathlib import Path
|
||||
from core.artifacts import set_plain_mode
|
||||
from core.deterministic_zip import FIXED_DATE_TIME
|
||||
from core.hashing import compute_hashes
|
||||
from core.paths import sanitize_pack_path
|
||||
from core.paths import comparable_destination, sanitize_pack_path
|
||||
from packs.paths import has_path_conflict, register_path, placement_block
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ class Placed:
|
||||
tree walk all place files through this one record.
|
||||
|
||||
``content``, when given, records the sha1 of what each taken path holds,
|
||||
keyed by its lowercased destination: a case twin carrying the same
|
||||
keyed by its folded destination: a case twin carrying the same
|
||||
bytes serves the core on a filesystem that folds the names.
|
||||
"""
|
||||
|
||||
@@ -159,16 +159,18 @@ class Placed:
|
||||
self.destinations.add(dest)
|
||||
register_path(dest, self.destinations, self.parents)
|
||||
if self.fold:
|
||||
self.lower.add(dest.lower())
|
||||
self.lower.add(comparable_destination(dest))
|
||||
if self.content is not None:
|
||||
self.content[dest.lower()] = sha1
|
||||
self.content[comparable_destination(dest)] = sha1
|
||||
|
||||
def content_at(self, dest: str) -> str | None:
|
||||
"""The sha1 recorded for the path a destination folds onto."""
|
||||
return (self.content or {}).get(dest.lower())
|
||||
return (self.content or {}).get(comparable_destination(dest))
|
||||
|
||||
def holds(self, dest: str) -> bool:
|
||||
return dest in self.destinations or (self.fold and dest.lower() in self.lower)
|
||||
return dest in self.destinations or (
|
||||
self.fold and comparable_destination(dest) in self.lower
|
||||
)
|
||||
|
||||
def conflicts(self, dest: str) -> bool:
|
||||
return has_path_conflict(dest, self.destinations, self.parents)
|
||||
|
||||
@@ -9,7 +9,7 @@ from __future__ import annotations
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import dataclass
|
||||
|
||||
from core.paths import sanitize_pack_path
|
||||
from core.paths import comparable_destination, sanitize_pack_path
|
||||
from resolve.validation import read_from_save_dir
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ def placement_block(
|
||||
"""
|
||||
if dest in seen_files:
|
||||
return "taken"
|
||||
if case_insensitive and dest.lower() in seen_lower:
|
||||
if case_insensitive and comparable_destination(dest) in seen_lower:
|
||||
return "case_twin"
|
||||
if has_path_conflict(dest, seen_files, seen_parents):
|
||||
return "path_conflict"
|
||||
|
||||
@@ -10,7 +10,8 @@ from core.hashing import parse_md5_list
|
||||
from model.profiles import entry_system_ids, lists_files
|
||||
from resolve import nativemode
|
||||
from resolve.archives import archive_entry, holds_required_members
|
||||
from resolve.collisions import accepted_by_all, content_sha1, lists_hashes, comparable_destination
|
||||
from core.paths import comparable_destination
|
||||
from resolve.collisions import accepted_by_all, content_sha1, lists_hashes
|
||||
from resolve.cores import resolve_platform_cores
|
||||
from resolve.layout import system_dir_path
|
||||
from resolve.localfile import resolution_is_hash_exact, resolve_local_file
|
||||
|
||||
@@ -7,21 +7,12 @@ import zlib
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from core.hashing import compute_hashes, parse_hash_list, parse_md5_list
|
||||
from core.paths import comparable_destination
|
||||
from core.ziptools import check_inside_zip
|
||||
from resolve.localfile import resolve_local_file, variant_base_name
|
||||
from resolve.packfiles import records_by_path, preferred_entries
|
||||
|
||||
|
||||
def comparable_destination(destination: str, fold: bool = True) -> str:
|
||||
"""Comparable form of a destination, since layers write it differently.
|
||||
|
||||
Case is folded only where the platform's filesystem folds it: on Linux
|
||||
RetroDECK ships bios/DISK.ROM and bios/disk.rom side by side.
|
||||
"""
|
||||
cleaned = destination.strip().strip("/").replace("\\", "/")
|
||||
return cleaned.casefold() if fold else cleaned
|
||||
|
||||
|
||||
@dataclass
|
||||
class Collision:
|
||||
"""One destination a platform fills with two different files."""
|
||||
|
||||
@@ -25,7 +25,7 @@ from model.declarations import CONFIGS_ROOT, ROMS_ROOT, declared_root, outer_lay
|
||||
from model.profiles import lists_files
|
||||
from resolve.content import name_match_size_ok
|
||||
from resolve.localfile import resolve_local_file
|
||||
from core.paths import sanitize_pack_path
|
||||
from core.paths import comparable_destination, sanitize_pack_path
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
# The kinds whose names say which file the launcher opens. A link of a named
|
||||
@@ -74,7 +74,7 @@ class LauncherPlace:
|
||||
passes_to: str = ""
|
||||
|
||||
def fold(self, name: str) -> str:
|
||||
return name.lower() if self.case_insensitive else name
|
||||
return comparable_destination(name, self.case_insensitive)
|
||||
|
||||
def basenames(self) -> set[str]:
|
||||
return {self.fold(p.rsplit("/", 1)[-1]) for p in self.paths}
|
||||
|
||||
Reference in new issue
Block a user