mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-28 12:28:51 -06:00
fix: follow moved retrodeck folders under --dest
A run given --platform and --dest never detects, so retrodeck.json was never read and a moved bios/ folder was ignored. MovedFolders looks the root up on first use, is reset per run, and detection only warms it.
This commit is contained in:
1 parent
9f3fc2e0c1
commit
c4a129e200
10 files changed
+177
-54
No files matched your search
@@ -26,7 +26,7 @@ from installer.detect_os import (
|
||||
_unix_retroarch_base,
|
||||
)
|
||||
from installer.host_fs import _SETUP_SEARCH, _exists, _host_path, _is_dir, _is_file, _note_refused
|
||||
from installer.paths import _record_moved_folders, shown_path
|
||||
from installer.paths import MOVED, RETRODECK_CONFIG, shown_path
|
||||
from installer.platforms import display_name
|
||||
from installer.text import _CONTROLS
|
||||
|
||||
@@ -683,9 +683,7 @@ def _detect_emudeck_unix(found: list[tuple[str, Path]]) -> None:
|
||||
|
||||
def _detect_retrodeck(home: Path, found: list[tuple[str, Path]]) -> None:
|
||||
"""Add RetroDECK's home folder."""
|
||||
# RetroDECK: retrodeck.json since the cfg-to-json migration, which
|
||||
# renames the old retrodeck.cfg to retrodeck.bak (global.sh:149-153)
|
||||
retrodeck_conf_dir = home / ".var" / "app" / "net.retrodeck.retrodeck" / "config" / "retrodeck"
|
||||
retrodeck_conf_dir = home / RETRODECK_CONFIG
|
||||
retrodeck_json = retrodeck_conf_dir / "retrodeck.json"
|
||||
retrodeck_cfg = retrodeck_conf_dir / "retrodeck.cfg"
|
||||
if _exists(retrodeck_json):
|
||||
@@ -698,7 +696,7 @@ def _detect_retrodeck(home: Path, found: list[tuple[str, Path]]) -> None:
|
||||
f"{retrodeck_json}: assuming {home / 'retrodeck'}",
|
||||
)
|
||||
rd_root = Path(rd_home) if rd_home else home / "retrodeck"
|
||||
_record_moved_folders(rd_root, retrodeck_json)
|
||||
MOVED.record(rd_root, retrodeck_json)
|
||||
found.append(("retrodeck", rd_root))
|
||||
elif _exists(retrodeck_cfg):
|
||||
rd_home = _parse_bash_var(retrodeck_cfg, "rdhome")
|
||||
|
||||
@@ -25,7 +25,7 @@ from installer.host_fs import (
|
||||
_is_file,
|
||||
refused_words,
|
||||
)
|
||||
from installer.paths import _MOVED_FOLDERS, shown_path
|
||||
from installer.paths import MOVED, shown_path
|
||||
from installer.platforms import display_name
|
||||
from installer.text import screen_text
|
||||
|
||||
@@ -363,7 +363,7 @@ def found_label(plat: str, path: Path) -> str:
|
||||
name = detected_shown(plat, path)
|
||||
shown = display_name(plat)
|
||||
moved = "".join(f", {folder}/ at {place}"
|
||||
for folder, place in sorted(_MOVED_FOLDERS.get(path, {}).items())
|
||||
for folder, place in sorted(MOVED.of(path).items())
|
||||
if folder in ("bios", "roms"))
|
||||
folder = shown_path(setup_bios_folder(plat, path))
|
||||
if not name or name == shown:
|
||||
|
||||
+68
-14
@@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import threading
|
||||
from pathlib import Path, PurePosixPath, PureWindowsPath
|
||||
from typing import NamedTuple
|
||||
|
||||
@@ -143,22 +144,23 @@ def _safe_target_dir(value: object, field: str) -> str:
|
||||
return value
|
||||
|
||||
|
||||
# A platform whose folders move one by one: root -> {folder under the root:
|
||||
# where it is now}. RetroDECK's per-folder move (RetroDECK 7786a849,
|
||||
# functions/api_data_processing.sh:913-935) records each new place in
|
||||
# retrodeck.json paths.<folder>_path (config/retrodeck/retrodeck.json:3-23),
|
||||
# and its manifest places files under bios/ and roms/ of the home folder.
|
||||
_MOVED_FOLDERS: dict[Path, dict[str, Path]] = {}
|
||||
# RetroDECK's settings folder below the home folder: retrodeck.json since the
|
||||
# cfg-to-json migration, which renames the old retrodeck.cfg to retrodeck.bak
|
||||
# (global.sh:149-153).
|
||||
RETRODECK_CONFIG = Path(".var") / "app" / "net.retrodeck.retrodeck" / "config" / "retrodeck"
|
||||
|
||||
|
||||
def _record_moved_folders(root: Path, retrodeck_json: Path) -> None:
|
||||
"""Each RetroDECK folder that is no longer <home>/<name>."""
|
||||
def _retrodeck_paths(retrodeck_json: Path) -> dict | None:
|
||||
"""The paths table of retrodeck.json, None when it cannot be read."""
|
||||
try:
|
||||
paths = json.loads(retrodeck_json.read_text(encoding="utf-8", errors="replace"))["paths"]
|
||||
except (OSError, ValueError, KeyError, TypeError):
|
||||
return
|
||||
if not isinstance(paths, dict):
|
||||
return
|
||||
return None
|
||||
return paths if isinstance(paths, dict) else None
|
||||
|
||||
|
||||
def _moved_in(root: Path, paths: dict) -> dict[str, Path]:
|
||||
"""Each RetroDECK folder that is no longer <home>/<name>."""
|
||||
moved = {}
|
||||
for key, value in paths.items():
|
||||
name = key[:-len("_path")] if key.endswith("_path") else ""
|
||||
@@ -166,8 +168,60 @@ def _record_moved_folders(root: Path, retrodeck_json: Path) -> None:
|
||||
place = Path(value.strip())
|
||||
if place != root / name:
|
||||
moved[name] = place
|
||||
if moved:
|
||||
_MOVED_FOLDERS[root] = moved
|
||||
return moved
|
||||
|
||||
|
||||
class MovedFolders:
|
||||
"""A platform whose folders move one by one: root -> {folder under the
|
||||
root: where it is now}.
|
||||
|
||||
RetroDECK's per-folder move (RetroDECK 7786a849,
|
||||
functions/api_data_processing.sh:913-935) records each new place in
|
||||
retrodeck.json paths.<folder>_path (config/retrodeck/retrodeck.json:3-23),
|
||||
and its manifest places files under bios/ and roms/ of the home folder.
|
||||
A root is looked up on first use, so a run given --dest that never
|
||||
detects places files where a detecting run does; detection only fills
|
||||
the cache ahead.
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._lock = threading.Lock()
|
||||
self._by_root: dict[Path, dict[str, Path]] = {}
|
||||
|
||||
def reset(self) -> None:
|
||||
with self._lock:
|
||||
self._by_root.clear()
|
||||
|
||||
def record(self, root: Path, retrodeck_json: Path) -> None:
|
||||
"""root's moved folders, as retrodeck_json lists them."""
|
||||
paths = _retrodeck_paths(retrodeck_json)
|
||||
with self._lock:
|
||||
self._by_root[root] = _moved_in(root, paths) if paths is not None else {}
|
||||
|
||||
def of(self, root: Path) -> dict[str, Path]:
|
||||
"""root's moved folders: none unless root is RetroDECK's home folder."""
|
||||
with self._lock:
|
||||
known = self._by_root.get(root)
|
||||
if known is not None:
|
||||
return known
|
||||
moved = self._look_up(root)
|
||||
with self._lock:
|
||||
return self._by_root.setdefault(root, moved)
|
||||
|
||||
@staticmethod
|
||||
def _look_up(root: Path) -> dict[str, Path]:
|
||||
home = Path.home()
|
||||
paths = _retrodeck_paths(home / RETRODECK_CONFIG / "retrodeck.json")
|
||||
if paths is None:
|
||||
return {}
|
||||
rd_home = paths.get("rd_home_path")
|
||||
rd_root = Path(rd_home) if isinstance(rd_home, str) and rd_home else home / "retrodeck"
|
||||
if os.path.abspath(rd_root) != os.path.abspath(root):
|
||||
return {}
|
||||
return _moved_in(root, paths)
|
||||
|
||||
|
||||
MOVED = MovedFolders()
|
||||
|
||||
|
||||
# Resolved folder -> the same folder as the run names it: /sdcard is a link
|
||||
@@ -212,7 +266,7 @@ def _destination_path(root: Path, value: object) -> Path:
|
||||
emulator reads it.
|
||||
"""
|
||||
relative = _safe_relative_path(value, "dest")
|
||||
moved = _MOVED_FOLDERS.get(root, {})
|
||||
moved = MOVED.of(root)
|
||||
if len(relative.parts) > 1 and relative.parts[0] in moved:
|
||||
return moved[relative.parts[0]].resolve() / Path(*relative.parts[1:])
|
||||
return _note_spelling(root) / Path(*relative.parts)
|
||||
|
||||
@@ -30,6 +30,7 @@ from installer.lists import ListFailure, load_targets
|
||||
from installer.offline import LOCAL
|
||||
from installer.pack import pack_path
|
||||
from installer.pack_source import pack_name_platforms
|
||||
from installer.paths import MOVED
|
||||
from installer.platforms import AVAILABLE_PLATFORMS, _NO_BIOS_FOLDER, display_name, normalize_platform
|
||||
from installer.refusal import Refusal
|
||||
from installer.run_files import _output_kind, needed_targets
|
||||
@@ -109,6 +110,7 @@ class _InstallRun:
|
||||
def _start_install(args: argparse.Namespace, real_stdout: TextIO) -> _InstallRun:
|
||||
"""The run's options completed, its terminal and its local sources opened."""
|
||||
KEPT.reset()
|
||||
MOVED.reset()
|
||||
# A namespace built by a caller that predates --for-games has neither.
|
||||
args.for_games = getattr(args, "for_games", None)
|
||||
args.required_only = getattr(args, "required_only", False)
|
||||
|
||||
@@ -29,7 +29,7 @@ from installer.host_fs import (
|
||||
)
|
||||
from installer.invocation import _INVOCATION
|
||||
from installer.local_check import _digest_file, expected_hashes
|
||||
from installer.paths import _MOVED_FOLDERS, _entry_path, _entry_place, _note_spelling, _safe_relative_path, spelled
|
||||
from installer.paths import MOVED, _entry_path, _entry_place, _note_spelling, _safe_relative_path, spelled
|
||||
from installer.text import _plural, format_size
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -262,7 +262,7 @@ def _kept_slot(root: Path, value: object) -> tuple[Path, PurePosixPath]:
|
||||
it, as _destination_path places it: a RetroDECK folder moved elsewhere
|
||||
is its own folder."""
|
||||
relative = _safe_relative_path(value, "dest")
|
||||
moved = _MOVED_FOLDERS.get(root, {})
|
||||
moved = MOVED.of(root)
|
||||
if len(relative.parts) > 1 and relative.parts[0] in moved:
|
||||
return moved[relative.parts[0]].resolve(), PurePosixPath(*relative.parts[1:])
|
||||
return _note_spelling(root), relative
|
||||
|
||||
Reference in new issue
Block a user