fix: refuse a missing --for-games folder up front

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 02:19:14 +01:00
1 parent 147916b6af
commit fed933daef
10 files changed
+92 -31

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "a618acce8197a5069faeba667ed15e571f07de0b5d2d1b7463da2d8511cab195"
$defaultInstallSha256 = "b7ae8e2b5137e2cb10da96be98eec4ec709386bb575fb3cce7f322f2c94fe797"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+28 -9
View File
@@ -19331,20 +19331,31 @@ def games_probe(plat: str, bios_path: Path, network: bool = True,
return None
def games_folder(given: Path) -> Path:
"""The folder --for-games names, as the run reads it."""
return Path(os.path.expanduser(str(given))).absolute()
def games_folder_refusal(given: object, platform: str) -> Refusal | None:
"""The refusal of a folder named with --for-games that cannot be opened,
or None. Asked before the run, as for --from and --pack: a typo fetched
the file list first, and an offline run blamed the list instead."""
if not isinstance(given, Path):
return None
folder = games_folder(given)
if _is_dir(folder):
return None
message = f"the games folder {folder} does not exist or cannot be opened"
return Refusal("games", "no_folder", platform, f"Error: {message}.", message=message)
def read_games(args: argparse.Namespace, plat: str, bios_path: Path, manifest: dict,
term: Terminal | None, os_type: str) -> GamesPlan | None:
"""The games of the card read for this run, their lines said. None when
there are none to read, or what they need cannot be known: the run then
keeps every file, and says so where --for-games asked."""
asked = args.for_games is not None
folder = args.for_games if isinstance(args.for_games, Path) else None
if folder is not None:
folder = Path(os.path.expanduser(str(folder))).absolute()
if not _is_dir(folder):
message = f"the games folder {folder} does not exist or cannot be opened"
EVENTS.emit("games_unavailable", platform=plat, reason="no_folder", message=message)
print(f"Error: {message}.", file=sys.stderr)
sys.exit(1)
folder = games_folder(args.for_games) if isinstance(args.for_games, Path) else None
# Not asked for, a run given its list as a file looks for the games index
# beside it and in the cache only: one fetched now could describe another
# list.
@@ -23477,6 +23488,9 @@ def _start_install(args: argparse.Namespace, real_stdout: TextIO) -> _InstallRun
_enter_wsl()
_wsl_dest(args)
_open_local_sources(args)
refusal = games_folder_refusal(args.for_games, args.platform or "")
if refusal is not None:
raise refusal
# --pack: the files go into a ZIP for another device, no folder of this
# machine is read or written, and nothing is asked.
packing = getattr(args, "pack", None) is not None
@@ -32326,7 +32340,7 @@ def run_tui(args: argparse.Namespace) -> int:
def _tui_startup(args: argparse.Namespace) -> tuple[TuiState, list[tuple]] | None:
"""The local sources opened and the first screen chosen, None when a
--from folder cannot be read (said on stderr)."""
--from or --for-games folder cannot be read (said on stderr)."""
os_type = _INVOCATION.os_type or detect_os()
if os_type == "wsl":
_enter_wsl()
@@ -32341,6 +32355,11 @@ def _tui_startup(args: argparse.Namespace) -> tuple[TuiState, list[tuple]] | Non
for line in refusal.lines:
print(line, file=sys.stderr)
return None
refusal = games_folder_refusal(getattr(args, "for_games", None), args.platform or "")
if refusal is not None:
for line in refusal.lines:
print(line, file=sys.stderr)
return None
return tui_start(args, os_type)
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="a618acce8197a5069faeba667ed15e571f07de0b5d2d1b7463da2d8511cab195"
DEFAULT_INSTALL_SHA256="b7ae8e2b5137e2cb10da96be98eec4ec709386bb575fb3cce7f322f2c94fe797"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1493467,
"sha256": "a618acce8197a5069faeba667ed15e571f07de0b5d2d1b7463da2d8511cab195",
"size": 1490208,
"sha256": "b7ae8e2b5137e2cb10da96be98eec4ec709386bb575fb3cce7f322f2c94fe797",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1547092,
"sha256": "4c4aa576277413d849cf173fe4fe9bbd7921e4994332adabdb0386b38cdea7ab"
"size": 1543833,
"sha256": "12a284b9c02227449541bf2fa0fd8413c14d77f3300db05e32487cc5dbc5cb04"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1493467,
"sha256": "a618acce8197a5069faeba667ed15e571f07de0b5d2d1b7463da2d8511cab195",
"size": 1490208,
"sha256": "b7ae8e2b5137e2cb10da96be98eec4ec709386bb575fb3cce7f322f2c94fe797",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1493467,
"sha256": "a618acce8197a5069faeba667ed15e571f07de0b5d2d1b7463da2d8511cab195",
"size": 1490208,
"sha256": "b7ae8e2b5137e2cb10da96be98eec4ec709386bb575fb3cce7f322f2c94fe797",
"executable": false
},
{
+20 -9
View File
@@ -7,7 +7,6 @@ import http.client
import json
import os
import re
import sys
import urllib.error
from collections.abc import Callable, Collection, Iterable
from pathlib import Path
@@ -41,6 +40,7 @@ from installer.network import _fetch_json, _read_capped
from installer.offline import LOCAL, _Offline, offline_words
from installer.paths import shown_path
from installer.platforms import entry_systems, system_title
from installer.refusal import Refusal
from installer.regions import WORLD_REGION, _region_comparable, region_title
from installer.remote import active_remote
from installer.text import _plural, agree
@@ -912,20 +912,31 @@ def games_probe(plat: str, bios_path: Path, network: bool = True,
return None
def games_folder(given: Path) -> Path:
"""The folder --for-games names, as the run reads it."""
return Path(os.path.expanduser(str(given))).absolute()
def games_folder_refusal(given: object, platform: str) -> Refusal | None:
"""The refusal of a folder named with --for-games that cannot be opened,
or None. Asked before the run, as for --from and --pack: a typo fetched
the file list first, and an offline run blamed the list instead."""
if not isinstance(given, Path):
return None
folder = games_folder(given)
if _is_dir(folder):
return None
message = f"the games folder {folder} does not exist or cannot be opened"
return Refusal("games", "no_folder", platform, f"Error: {message}.", message=message)
def read_games(args: argparse.Namespace, plat: str, bios_path: Path, manifest: dict,
term: Terminal | None, os_type: str) -> GamesPlan | None:
"""The games of the card read for this run, their lines said. None when
there are none to read, or what they need cannot be known: the run then
keeps every file, and says so where --for-games asked."""
asked = args.for_games is not None
folder = args.for_games if isinstance(args.for_games, Path) else None
if folder is not None:
folder = Path(os.path.expanduser(str(folder))).absolute()
if not _is_dir(folder):
message = f"the games folder {folder} does not exist or cannot be opened"
EVENTS.emit("games_unavailable", platform=plat, reason="no_folder", message=message)
print(f"Error: {message}.", file=sys.stderr)
sys.exit(1)
folder = games_folder(args.for_games) if isinstance(args.for_games, Path) else None
# Not asked for, a run given its list as a file looks for the games index
# beside it and in the cache only: one fetched now could describe another
# list.
+4
View File
@@ -17,6 +17,7 @@ from installer.detect_frontends import detect_frontends, detect_platforms
from installer.detect_os import _enter_wsl, _os_name, _system_lines, _wsl_dest, detect_os, detected_os, found_label
from installer.events import EVENTS
from installer.from_folders import _open_local_sources
from installer.games import games_folder_refusal
from installer.handheld_app import app_refusal
from installer.install_record import by_record, drop_recorded
from installer.invocation import _INVOCATION, Invocation, installer_id
@@ -159,6 +160,9 @@ def _start_install(args: argparse.Namespace, real_stdout: TextIO) -> _InstallRun
_enter_wsl()
_wsl_dest(args)
_open_local_sources(args)
refusal = games_folder_refusal(args.for_games, args.platform or "")
if refusal is not None:
raise refusal
# --pack: the files go into a ZIP for another device, no folder of this
# machine is read or written, and nothing is asked.
packing = getattr(args, "pack", None) is not None
+7 -1
View File
@@ -33,6 +33,7 @@ from installer.detect_frontends import detect_frontends
from installer.detection_notes import DETECTION_NOTES, detection_held
from installer.detect_os import _enter_wsl, _wsl_dest, detect_os, detected_os
from installer.from_folders import from_folder_refusal, open_list_and_pack, reset_local_sources
from installer.games import games_folder_refusal
from installer.host_fs import _DETECTION_REFUSED, refused_words
from installer.install_record import choice_given
from installer.invocation import _INVOCATION, OFFLINE_VARIABLE
@@ -877,7 +878,7 @@ def run_tui(args: argparse.Namespace) -> int:
def _tui_startup(args: argparse.Namespace) -> tuple[TuiState, list[tuple]] | None:
"""The local sources opened and the first screen chosen, None when a
--from folder cannot be read (said on stderr)."""
--from or --for-games folder cannot be read (said on stderr)."""
os_type = _INVOCATION.os_type or detect_os()
if os_type == "wsl":
_enter_wsl()
@@ -892,6 +893,11 @@ def _tui_startup(args: argparse.Namespace) -> tuple[TuiState, list[tuple]] | Non
for line in refusal.lines:
print(line, file=sys.stderr)
return None
refusal = games_folder_refusal(getattr(args, "for_games", None), args.platform or "")
if refusal is not None:
for line in refusal.lines:
print(line, file=sys.stderr)
return None
return tui_start(args, os_type)
+11
View File
@@ -862,6 +862,17 @@ class CommandLine(unittest.TestCase):
self.assertEqual(proc.returncode, 1)
self.assertIn("does not exist", proc.stderr)
def test_a_games_folder_that_does_not_exist_is_refused_before_the_list(self):
# Refused as --from is, before the list: offline with no list at hand,
# the run named the list and never the folder.
shutil.rmtree(self.card.lists)
proc = run_cli(self.card, "--for-games", str(self.card.root / "nowhere"), "--check",
"--events")
self.assertEqual(proc.returncode, 1)
errors = [e for e in self.events(proc) if e["event"] == "error"]
self.assertEqual([(e["stage"], e["reason"]) for e in errors], [("games", "no_folder")])
self.assertEqual(proc.stderr.count("does not exist or cannot be opened"), 1)
def test_offline_without_the_index_keeps_every_file_and_says_so(self):
shutil.rmtree(self.card.lists / "games")
proc = run_cli(self.card, "--for-games", "--check", "--events")
+10
View File
@@ -3392,6 +3392,16 @@ class CardsSpaceAndConfirm(unittest.TestCase):
self.assertEqual(install.run_tui(_args(**{"from": [missing]})), 1)
self.assertIn(f"Error: {missing} does not exist: --from names the folder", err.getvalue())
def test_a_games_folder_that_does_not_exist_closes_before_the_first_frame(self):
missing = REPO_ROOT / "tmp" / "no-such-games-folder"
err = io.StringIO()
with mock.patch.object(install, "detect_os", return_value="linux"), \
mock.patch.object(install, "tui_start", side_effect=AssertionError("opened")), \
mock.patch.object(sys, "stderr", err):
self.assertEqual(install.run_tui(_args(for_games=missing)), 1)
self.assertIn(f"Error: the games folder {missing} does not exist or cannot be opened.",
err.getvalue())
# Work folders: only a kill no handler sees leaves one, and the next
# run takes it away.
+2 -2
View File
@@ -2229,7 +2229,7 @@ other schemas under `api/v1/schemas/`.
| `start` | `schema`, `installer`, `mode` | First line. `schema` is 1, `installer` the identity `--version` prints, `mode` one of `install`, `check`, `dry-run`, `list` (also `--backups`), `remove` (`--remove`, `--delete-backup`), `restore`, `pack` (`--pack`, with `--dry-run` too) |
| `unsearched` | `folder`, `reason`, `message` | Before `detect`, once for each folder the search for setups could not look in, this user being refused it or a read failing there (a failing card, a link that loops), or under WSL the Windows side when Windows did not answer (`folder` is then the drive mount, `/mnt`). What it would hold counts as absent, and the other places are still searched: `detect` then lists what they hold, and an empty `platforms` after an `unsearched` line means nothing was found where the installer could look. `reason` says why in words (`Permission denied`), `message` says it in a sentence |
| `detect` | `os`, `os_name`, `platforms` | Once the platforms are known. `os_name` comes from `/etc/os-release`. `platforms` lists `{platform, name, bios_dir}`, and is empty when nothing supported was found |
| `error` | `stage`, `reason`, `platform`, `message` | The file list could not be read (`stage` is `manifest`): `reason` is `network`, `not_found` or `invalid`, `clock` when the server's certificate was refused and the system clock reads a date before the installer was written, `no_ca` when the machine holds no list of trusted certificates (`SSL_CERT_FILE` names one), `no_ssl` when this Python was built without its `ssl` module and cannot use HTTPS, or `offline` when `--offline` forbids the request. A `--manifest` file that cannot be read carries `reason` `unreadable`, and the standalone layout `--standalone` needs `unavailable`. A folder named with `--from` cannot be read (`stage` is `from`, `reason` `not_found`, `not_a_folder` for a file that is no ZIP, `unreadable`, or `system` for the root of the system, `/proc`, `/sys` or `/dev`). The BIOS folder sits under a folder this user cannot open (`stage` is `dest`, `reason` `unreadable`), or is a file or lies under one (`reason` `not_a_folder`), and the run ends with code 1 before anything is written. A platform, target, system, core or emulator named on the command line is unknown or cannot be used here (`stage` is `option`, `reason` `unknown`, `platform` the platform it was checked against or the name typed), refused before any download with code 2, or a `--find` hash no one file of the list holds (code 4). An option that does not apply to the run, `--romm-firmware` without RomM or `--installed-cores` for a system that ships its cores (`stage` is `option`, `reason` `not_applicable`), or a `--romm-firmware` value it cannot read (`reason` `invalid`), code 1. A `--remove` or `--delete-backup` without `--yes` where no question can be asked (`stage` is `option`, `reason` `needs_yes`, code 2). The list does not record what `--system`, `--core`, `--region`, `--emulator`, `--standalone`, `--source truth`, `--no-game-data`, `--installed-cores` or `--one-per-slot` reads (`stage` is `option`, `reason` `not_recorded`, code 1). `--installed-cores` finds no core (`stage` is `cores`, `reason` `none`), or its `--cores-dir` does not exist, is not a folder or cannot be read (`reason` `not_found`, `not_a_folder` or `unreadable`). The board list a run needs cannot be had (`stage` is `targets`, `reason` as for the file list, `http` for a refused answer). The `--from-pack` file is no pack, is a pack of another platform, or names no platform and none is given (`stage` is `pack`, `reason` `invalid`, `other_platform` or `no_platform`), as for a `--pack` whose name gives no platform (code 2). A `--delete-backup` folder is not one the installer kept files in (`stage` is `backup`, `reason` `not_a_backup`, code 2). The BIOS folder cannot be created (`stage` is `dest`, `reason` `not_writable`). Two systems are detected on one machine and no `--dest` names the folder, or a `--dest` given alone finds several here (`stage` is `detect`, `reason` `conflict`), as are `--remove` and `--backups` finding several setups and none named (`not_found` for none), with code 2. The platform named with `--platform` is found nowhere and no folder can be assumed for it: a card system with no card named, a portable emulator, Batocera or Recalbox named on a computer (their folder is the `bios` folder of their SHARE drive), or no usual folder on this system or one set aside behind a folder this user cannot open (`stage` is `detect`, `reason` `not_found`). So is a platform named by a file list or a pack, in a run without questions where it is found nowhere here. A `--dest` refused as the card of the system named carries the same `stage` and `reason`: another system's card, a folder inside a card, a drive with none of the files its card always has, or a folder that does not exist. The drive holding the BIOS folder cannot hold the download (`stage` is `space`, `reason` `drive_full`), right after `no_space`, before any file of the setup is written. Once a setup reached its first write, its space check included, an `error` that stops the run is followed by `failures` and a `summary` of what the run installed before it, as at its end. `message` says it in words, and is the only thing that tells these cases apart |
| `error` | `stage`, `reason`, `platform`, `message` | The file list could not be read (`stage` is `manifest`): `reason` is `network`, `not_found` or `invalid`, `clock` when the server's certificate was refused and the system clock reads a date before the installer was written, `no_ca` when the machine holds no list of trusted certificates (`SSL_CERT_FILE` names one), `no_ssl` when this Python was built without its `ssl` module and cannot use HTTPS, or `offline` when `--offline` forbids the request. A `--manifest` file that cannot be read carries `reason` `unreadable`, and the standalone layout `--standalone` needs `unavailable`. A folder named with `--from` cannot be read (`stage` is `from`, `reason` `not_found`, `not_a_folder` for a file that is no ZIP, `unreadable`, or `system` for the root of the system, `/proc`, `/sys` or `/dev`). The `FOLDER` named with `--for-games` does not exist or cannot be opened (`stage` is `games`, `reason` `no_folder`), refused before the file list is read, with code 1. The BIOS folder sits under a folder this user cannot open (`stage` is `dest`, `reason` `unreadable`), or is a file or lies under one (`reason` `not_a_folder`), and the run ends with code 1 before anything is written. A platform, target, system, core or emulator named on the command line is unknown or cannot be used here (`stage` is `option`, `reason` `unknown`, `platform` the platform it was checked against or the name typed), refused before any download with code 2, or a `--find` hash no one file of the list holds (code 4). An option that does not apply to the run, `--romm-firmware` without RomM or `--installed-cores` for a system that ships its cores (`stage` is `option`, `reason` `not_applicable`), or a `--romm-firmware` value it cannot read (`reason` `invalid`), code 1. A `--remove` or `--delete-backup` without `--yes` where no question can be asked (`stage` is `option`, `reason` `needs_yes`, code 2). The list does not record what `--system`, `--core`, `--region`, `--emulator`, `--standalone`, `--source truth`, `--no-game-data`, `--installed-cores` or `--one-per-slot` reads (`stage` is `option`, `reason` `not_recorded`, code 1). `--installed-cores` finds no core (`stage` is `cores`, `reason` `none`), or its `--cores-dir` does not exist, is not a folder or cannot be read (`reason` `not_found`, `not_a_folder` or `unreadable`). The board list a run needs cannot be had (`stage` is `targets`, `reason` as for the file list, `http` for a refused answer). The `--from-pack` file is no pack, is a pack of another platform, or names no platform and none is given (`stage` is `pack`, `reason` `invalid`, `other_platform` or `no_platform`), as for a `--pack` whose name gives no platform (code 2). A `--delete-backup` folder is not one the installer kept files in (`stage` is `backup`, `reason` `not_a_backup`, code 2). The BIOS folder cannot be created (`stage` is `dest`, `reason` `not_writable`). Two systems are detected on one machine and no `--dest` names the folder, or a `--dest` given alone finds several here (`stage` is `detect`, `reason` `conflict`), as are `--remove` and `--backups` finding several setups and none named (`not_found` for none), with code 2. The platform named with `--platform` is found nowhere and no folder can be assumed for it: a card system with no card named, a portable emulator, Batocera or Recalbox named on a computer (their folder is the `bios` folder of their SHARE drive), or no usual folder on this system or one set aside behind a folder this user cannot open (`stage` is `detect`, `reason` `not_found`). So is a platform named by a file list or a pack, in a run without questions where it is found nowhere here. A `--dest` refused as the card of the system named carries the same `stage` and `reason`: another system's card, a folder inside a card, a drive with none of the files its card always has, or a folder that does not exist. The drive holding the BIOS folder cannot hold the download (`stage` is `space`, `reason` `drive_full`), right after `no_space`, before any file of the setup is written. Once a setup reached its first write, its space check included, an `error` that stops the run is followed by `failures` and a `summary` of what the run installed before it, as at its end. `message` says it in words, and is the only thing that tells these cases apart |
| `no_space` | `platform`, `folder`, `bytes_needed`, `bytes_free` | Right before the `error` of `stage` `space`: the BIOS folder, the bytes the run writes there and the bytes free on its drive. `platform` is empty for a standalone build's folder |
| `scanned` | `folder`, `files`, `truncated`, `other_drives` | Each folder named with `--from`, once read and before `detect`. `files` counts the files found, `truncated` is true when the search stopped at 200,000 of them, and `other_drives` lists the folders below it on another drive, which were not entered |
| `version` | `platform`, `list_version`, `installed_version`, `message` | Before `choices`, when the system here runs another version than the one the list was built for: `list_version` is the list's, `installed_version` the one the system's version file states, and `message` says it and what it means. Not written when either version is unknown. The run goes on |
@@ -2242,7 +2242,7 @@ other schemas under `api/v1/schemas/`.
| `checking` | `files_done`, `files_total` | While the files already in the folder are read and hashed, at most every half second and once at the end. `files_total` counts the files found in place |
| `games_reading` | `files_done`, `files_total` | With `--for-games`, while the games of the card are read (a cartridge hashed, a disc's header read), at most every half second and once at the end |
| `games` | `platform`, `folder`, `games`, `recognised`, `found`, `fallback`, `not_games`, `required_only` | With `--for-games`, once the games are read, before `choices`. `found` lists per system its `folder`, `games`, `recognised` and the `regions` kept (empty for every region). `fallback` names each game that got every BIOS of its system, with a `reason` (`not_recognised`, `not_read`, `region_unknown`, `unknown_set`, `no_parent`) |
| `games_unavailable` | `platform`, `reason`, `message` | With `--for-games`, what the games need could not be read (`offline`, `network`, `invalid`, `stale`, `no_sets`, `no_folder`): the run keeps every file of the list, except for a `FOLDER` that does not exist, where it stops |
| `games_unavailable` | `platform`, `reason`, `message` | With `--for-games`, what the games need could not be read (`offline`, `network`, `invalid`, `stale`, `no_sets`, `no_folder`): the run keeps every file of the list |
| `check` | `platform`, `name`, `bios_dir`, `files`, `present`, `missing`, `wrong_hash`, `bytes_needed`, `data_missing`, `not_installable` | The platform's totals. `data_missing` counts data-tree files to fetch, `not_installable` the files the collection cannot supply |
| `declared` | `platform`, `files`, `present`, `missing`, `wrong_hash`, `bytes_needed`, `dests` | Right after `check`, the same counts over the files the platform's own list names (`cores: null`), and their `dests` in the order of the `file` events. A setup that checks its own list reads its answer here, with or without `--declared-only` |
| `data` | `platform`, `files`, `bytes` | Right after `declared`: the data-tree files to fetch (the `data_missing` of `check`) and the bytes fetching them costs: each tree's archive, or the files themselves from a pack or a list that records no archive size |