fix: a full drive is an event, not stderr text

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 19:51:02 +01:00
1 parent 0b0bf29089
commit 8fc294ef97
15 files changed
+457 -491

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 = "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854"
$defaultInstallSha256 = "37c49265a0703e8a8edd2000bc0583b0e9b44728e1519924c70b4e760c574179"
# 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
+339 -459
View File
File diff suppressed because it is too large. Load diff
+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="bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854"
DEFAULT_INSTALL_SHA256="37c49265a0703e8a8edd2000bc0583b0e9b44728e1519924c70b4e760c574179"
# 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": 1461669,
"sha256": "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854",
"size": 1462824,
"sha256": "37c49265a0703e8a8edd2000bc0583b0e9b44728e1519924c70b4e760c574179",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1515294,
"sha256": "6f00452c27a790eb8c6f38d1d30dddac00dd666f4b7fdf214706a1088f268eb5"
"size": 1516449,
"sha256": "ec17df57bd0930f22b22298402910b95684f260054895a10f695f38472715085"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1461669,
"sha256": "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854",
"size": 1462824,
"sha256": "37c49265a0703e8a8edd2000bc0583b0e9b44728e1519924c70b4e760c574179",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1461669,
"sha256": "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854",
"size": 1462824,
"sha256": "37c49265a0703e8a8edd2000bc0583b0e9b44728e1519924c70b4e760c574179",
"executable": false
},
{
+7 -1
View File
@@ -42,8 +42,14 @@ EVENT_KEYS: dict[str, tuple[str, ...]] = {
# targets (the board list a run cannot go on without, reason: the
# manifest's codes, http for a refused answer) or pack (--from-pack,
# reason: invalid, other_platform for a pack of another platform, or
# no_platform when none is named and the pack does not say).
# no_platform when none is named and the pack does not say) or space
# (reason: drive_full, the drive cannot hold the download, after
# no_space, before any file of the setup is written).
"error": ("stage", "reason", "platform", "message"),
# Right before the error of stage space: the BIOS folder, and the bytes
# the run needs and the drive has free. A kind of its own, since schema
# 1 never adds a key to error.
"no_space": ("platform", "folder", "bytes_needed", "bytes_free"),
# A folder named with --from, once read: the files it holds (counted
# up to MAX_SCANNED_FILES, truncated past them), and the folders below
# it on another drive, not entered.
+10 -3
View File
@@ -7,6 +7,7 @@ from pathlib import Path
from typing import TYPE_CHECKING
from installer.datadirs import data_fetch_bytes
from installer.events import EVENTS
from installer.invocation import _INVOCATION
from installer.narrowing import _filter_by_target
from installer.offline import LOCAL, _offline_only, offline_named, offline_undo
@@ -14,7 +15,7 @@ from installer.outcome import EVERYTHING_IN_PLACE
from installer.paths import shown_path
from installer.plan_words import _sized
from installer.platforms import OTHER_TITLE, entry_systems, system_title
from installer.space import free_space
from installer.space import space_shortfall
from installer.tally import _bytes, parts_words, tally
from installer.terminal import terminal_size
from installer.text import _plural, cell_width, format_size
@@ -242,9 +243,15 @@ def _check_free_space(bios_path: Path, needed: int, plat: str = "", code: int =
the status a script reads as "nothing installed", 1 after an earlier
platform of the run installed files.
"""
free = free_space(bios_path)
if free is None or free >= needed:
shortfall = space_shortfall(bios_path, needed)
if shortfall is None:
return
free = shortfall[1]
EVENTS.emit("no_space", platform=plat, folder=str(bios_path), bytes_needed=needed,
bytes_free=free)
EVENTS.emit("error", stage="space", reason="drive_full", platform=plat,
message=f"Not enough space on the drive holding {bios_path}: "
f"{format_size(needed)} needed, {format_size(free)} free.")
print(f"\nNot enough space on the drive holding {bios_path}.", file=sys.stderr)
print(f" Needed: {format_size(needed)}. Free: {format_size(free)}.",
file=sys.stderr)
+7
View File
@@ -26,3 +26,10 @@ def free_space(bios_path: Path) -> int | None:
return shutil.disk_usage(_nearest_folder(bios_path)).free
except OSError:
return None
def space_shortfall(bios_path: Path, needed: int) -> tuple[int, int] | None:
"""Needed and free when the drive holding bios_path cannot hold needed
bytes, else None, also when its free space cannot be told."""
free = free_space(bios_path)
return None if free is None or free >= needed else (needed, free)
+7 -15
View File
@@ -1,7 +1,6 @@
"""The result screen: what an install, a pack or a More action did, in words."""
from __future__ import annotations
import re
from pathlib import Path
from typing import TYPE_CHECKING, NamedTuple
@@ -38,24 +37,17 @@ from installer.tui_routes import TUI_PAD_ROUTES
if TYPE_CHECKING:
from installer.tui_state import TuiState
_SPACE_NEEDED = re.compile(r"Needed: (\S+ \S+)\. Free: (\S+ \S+)\.")
def _space_stop(state: TuiState) -> re.Match | None:
"""Needed and free, when the run stopped for lack of space."""
return next(filter(None, (_SPACE_NEEDED.search(line) for line in state.tail)), None)
def full_drive_words(state: TuiState) -> str:
"""The run's stop for lack of space, in words, "" for another stop: read
once, when the run ends."""
match = _space_stop(state)
if match is None:
"""The run's stop for lack of space (its no_space event), in words, ""
for another stop: read once, when the run ends."""
if state.no_space is None:
return ""
needed, free = state.no_space
dest = (state.dest or Path(".")).absolute()
card = any((mount == dest or mount in dest.parents) and card_system(mount)
for mount in _mounted_cards())
return f"The {'card' if card else 'drive'} is full: {match[1]} needed, {match[2]} free."
return (f"The {'card' if card else 'drive'} is full: {format_size(needed)} needed, "
f"{format_size(free)} free.")
def _tui_sources(state: TuiState, installed: int, missing: int, wrong: int = 0,
@@ -428,7 +420,7 @@ def tui_keeps_log(state: TuiState) -> bool:
return True
# A full card is said in words on the screen: its log adds nothing.
return (bool(state.log) and state.code not in (0, 130, None)
and _space_stop(state) is None)
and not state.full_drive)
def _removal_text(state: TuiState) -> list:
+4
View File
@@ -177,6 +177,9 @@ def _take_event(state: TuiState, event: dict) -> None:
if _take_action_event(state, event):
return
kind = event.get("event")
if kind == "no_space":
state.no_space = (event["bytes_needed"], event["bytes_free"])
return
if kind == "checking" and state.run in ("check", "install"):
state.reading = (event["files_done"], event["files_total"])
elif kind == "games_reading" and state.run in ("check", "install"):
@@ -315,6 +318,7 @@ def tui_receive(state: TuiState, message: tuple) -> list[tuple]:
state.tail = [line for line in tail if not line.startswith("RetroBIOS ")]
tail = state.tail
state.full_drive = full_drive_words(state)
state.no_space = None
if state.run in TUI_ACTION_RUNS:
return _action_ended(state, code, tail)
if state.run == "check":
+2
View File
@@ -286,6 +286,8 @@ class TuiState:
# The run's stop for lack of space in words, read when it ended: the
# result screen looked through the mounted drives on every frame.
self.full_drive: str = ""
# Needed and free bytes, from the no_space event of the run going on.
self.no_space: tuple[int, int] | None = None
self.log: str = ""
self.exit_code: int | None = None
# The RetroBIOS app on the card the BIOS folder is on: asked for
+34
View File
@@ -14,6 +14,7 @@
"unsearched",
"detect",
"error",
"no_space",
"scanned",
"version",
"board",
@@ -62,6 +63,9 @@
{
"$ref": "#/$defs/error"
},
{
"$ref": "#/$defs/no_space"
},
{
"$ref": "#/$defs/scanned"
},
@@ -271,6 +275,36 @@
}
}
},
"no_space": {
"type": "object",
"additionalProperties": false,
"required": [
"event",
"platform",
"folder",
"bytes_needed",
"bytes_free"
],
"properties": {
"event": {
"const": "no_space"
},
"platform": {
"type": "string"
},
"folder": {
"type": "string"
},
"bytes_needed": {
"type": "integer",
"minimum": 0
},
"bytes_free": {
"type": "integer",
"minimum": 0
}
}
},
"scanned": {
"type": "object",
"additionalProperties": false,
+1 -1
View File
@@ -37,7 +37,7 @@ KEY_TYPES: dict[str, dict] = {
**dict.fromkeys((
"files", "files_done", "files_total", "bytes", "bytes_done", "bytes_total",
"bytes_local", "bytes_network", "size", "present", "missing", "wrong_hash",
"bytes_needed", "data_missing", "not_installable", "installed", "up_to_date",
"bytes_needed", "bytes_free", "data_missing", "not_installable", "installed", "up_to_date",
"pending", "code", "games", "recognised", "not_games", "gone",
), _COUNT),
**dict.fromkeys(("truncated", "ok", "interrupted", "required_only", "applied", "info",
+14
View File
@@ -454,6 +454,20 @@ class TestFreeSpaceGuard(unittest.TestCase):
self.assertIn("Free", out)
self.assertIn("--dest", out)
def test_short_of_space_is_an_event_with_both_numbers(self):
"""A --events reader got only end code 2, like any other stop."""
install.shutil.disk_usage = lambda _p: SimpleNamespace(free=1_000)
events = io.StringIO()
with unittest.mock.patch.object(install.EVENTS, "stream", events), \
contextlib.redirect_stderr(io.StringIO()), self.assertRaises(SystemExit):
install._check_free_space(self.root, 5_000, "batocera")
said = [json.loads(line) for line in events.getvalue().splitlines()]
self.assertEqual(said[0], {"event": "no_space", "platform": "batocera",
"folder": str(self.root), "bytes_needed": 5_000,
"bytes_free": 1_000})
self.assertEqual((said[1]["event"], said[1]["stage"], said[1]["reason"]),
("error", "space", "drive_full"))
def test_probe_climbs_to_an_existing_ancestor(self):
missing = self.root / "not" / "created" / "yet"
out, code = self._run(free=1, needed=2, path=missing)
+20 -1
View File
@@ -2998,6 +2998,10 @@ class CardsSpaceAndConfirm(unittest.TestCase):
state.dest, state.log = root / "MUOS" / "bios", "/tmp/retrobios-tui-x/install.log"
state.stack.append("result")
state.code, state.tail = 2, list(self.FULL_TAIL)
install._take_event(state, {"event": "no_space", "platform": "retroarch",
"folder": str(state.dest),
"bytes_needed": 1200 * 1024 * 1024,
"bytes_free": 300 * 1024 * 1024})
with mock.patch.object(install, "_mounted_cards", return_value=[root]):
state.full_drive = install.full_drive_words(state)
title, lines = install.tui_outcome(state)
@@ -3009,6 +3013,21 @@ class CardsSpaceAndConfirm(unittest.TestCase):
self.assertNotIn(raw, text)
self.assertFalse(install.tui_keeps_log(state))
def test_a_reworded_space_line_leaves_the_stop_unchanged(self):
"""The result read "Needed: X. Free: Y." from the run's stderr: the
numbers come from the no_space event, whatever the line says."""
state = checked_state()
state.dest = self.card({}) / "bios"
install._take_event(state, {"event": "no_space", "platform": "retroarch",
"folder": str(state.dest), "bytes_needed": 90010,
"bytes_free": 36 * 1024})
state.tail = ["Not enough room."]
with mock.patch.object(install, "_mounted_cards", return_value=[]):
words = install.full_drive_words(state)
self.assertEqual(words, "The drive is full: 87.9 KB needed, 36.0 KB free.")
state.no_space, state.tail = None, list(self.FULL_TAIL)
self.assertEqual(install.full_drive_words(state), "")
def test_advice_never_names_the_interface_list(self):
if hasattr(os, "geteuid") and os.geteuid() == 0:
self.skipTest("root writes to a read-only folder")
@@ -9649,7 +9668,7 @@ class PacksWordingAndDocs(unittest.TestCase):
press(state, "enter")
view = " ".join(install.tui_view(state, 120, 40))
state.stack = ["result"]
state.tail = ["Needed: 87.9 KB. Free: 36.0 KB."]
state.no_space = (90010, 36 * 1024)
state.full_drive = install.full_drive_words(state)
_title, lines = install.tui_outcome(state)
self.assertEqual(state.card_bound, ("Onion", "BIOS"))
+2 -1
View File
@@ -2225,7 +2225,8 @@ 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. The list does not record what `--system`, `--core`, `--region`, `--emulator` or `--standalone` 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`). The BIOS folder cannot be created (`stage` is `dest`, `reason` `not_writable`): a `summary` follows with what the run installed before it. 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`). 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. `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 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. The list does not record what `--system`, `--core`, `--region`, `--emulator` or `--standalone` 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`). The BIOS folder cannot be created (`stage` is `dest`, `reason` `not_writable`): a `summary` follows with what the run installed before it. 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`). 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. `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 |
| `board` | `platform`, `board`, `applied`, `message` | Before `choices`, with no `--target` and no `--every-board`, when the system names its board or a Batocera or KNULLI card mounted here does (`boot/batocera.board` or `boot/knulli.board` on its boot partition, `board` then being the board its image maps to): `applied` is true when the run keeps that board's files only, false for a board the platform's list does not name, which keeps every board's files. `message` says it |