fix: read on-card once with the folder facts

The plan rows, plan text and result screen asked on every frame whether the BIOS folder sits on its system's card, scanning the mounted drives each time. A card pulled out while the plan was open moved Check again from under the focus. The answer is now read with the other folder facts at the end of the check.
This commit is contained in:
Abdessamad Derraz committed 2026-11-24 00:29:38 +01:00
1 parent 06f87cf957
commit 0d0b6c54b7
7 files changed
+59 -29

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 = "c56f884f958819a641571ee75eeee8b14b6ecd24e2fd24229944418c104c3cb9"
$defaultInstallSha256 = "aacb100cb625bc36fd7c9fa61de44949d23490c7ca09c2501e2321c6f72077a1"
# 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
+9 -7
View File
@@ -25129,11 +25129,9 @@ def _tui_card_bound(state: TuiState) -> tuple[str, str] | None:
def _on_its_card(state: TuiState) -> bool:
"""Whether the BIOS folder is on the SD card of the setup it is for, a
system that reads that card alone: room is made there, another folder
being one it never reads."""
if state.dest is None:
return False
return on_its_card(state.platform, state.dest,
state.card_bound[0] if state.card_bound else "")
being one it never reads. Read with the folder facts at the end of the
check, so every frame of the plan and the result shows the same rows."""
return state.dest is not None and bool(state.facts.get("on_card"))
def _dest_card(state: TuiState) -> Path | None:
@@ -29796,9 +29794,13 @@ def _tui_folder_facts(state: TuiState) -> dict:
free = None
cores = (installed_cores(core_dirs(state.platform, dest))
if state.platform in CORE_PLATFORMS else [])
# The retroarch.cfg that names dest, said under it on the plan.
# The retroarch.cfg that names dest, said under it on the plan. Whether
# dest is the card of its system is read here with the rest, never by
# a frame: a card pulled out moved the plan rows under the focus.
return {"free": free, "writable": _folder_writable(dest), "cores": cores,
"config": _retroarch_config_at(dest)}
"config": _retroarch_config_at(dest),
"on_card": on_its_card(state.platform, dest,
state.card_bound[0] if state.card_bound else "")}
def _row_folder(row: TuiRow) -> Path:
+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="c56f884f958819a641571ee75eeee8b14b6ecd24e2fd24229944418c104c3cb9"
DEFAULT_INSTALL_SHA256="aacb100cb625bc36fd7c9fa61de44949d23490c7ca09c2501e2321c6f72077a1"
# 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": 1488472,
"sha256": "c56f884f958819a641571ee75eeee8b14b6ecd24e2fd24229944418c104c3cb9",
"size": 1488785,
"sha256": "aacb100cb625bc36fd7c9fa61de44949d23490c7ca09c2501e2321c6f72077a1",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1542097,
"sha256": "5c45dcaa61b1853642902536ef01c0d7069f03c8767b54ac5416c32b0de75a29"
"size": 1542410,
"sha256": "91808aad8fa4b58666d46b6e519ac6d272d124f23ffcf2cf72712d02aa813ba8"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1488472,
"sha256": "c56f884f958819a641571ee75eeee8b14b6ecd24e2fd24229944418c104c3cb9",
"size": 1488785,
"sha256": "aacb100cb625bc36fd7c9fa61de44949d23490c7ca09c2501e2321c6f72077a1",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1488472,
"sha256": "c56f884f958819a641571ee75eeee8b14b6ecd24e2fd24229944418c104c3cb9",
"size": 1488785,
"sha256": "aacb100cb625bc36fd7c9fa61de44949d23490c7ca09c2501e2321c6f72077a1",
"executable": false
},
{
+7 -2
View File
@@ -29,6 +29,7 @@ from installer.destination import (
dest_drive,
missing_folder,
mounted_cards_of,
on_its_card,
)
from installer.detect_os import _DETECTED_OS, _FROM_CARD, detected_os, detected_shown
from installer.embedded import CARD_PLATFORMS, _a
@@ -763,9 +764,13 @@ def _tui_folder_facts(state: TuiState) -> dict:
free = None
cores = (installed_cores(core_dirs(state.platform, dest))
if state.platform in CORE_PLATFORMS else [])
# The retroarch.cfg that names dest, said under it on the plan.
# The retroarch.cfg that names dest, said under it on the plan. Whether
# dest is the card of its system is read here with the rest, never by
# a frame: a card pulled out moved the plan rows under the focus.
return {"free": free, "writable": _folder_writable(dest), "cores": cores,
"config": _retroarch_config_at(dest)}
"config": _retroarch_config_at(dest),
"on_card": on_its_card(state.platform, dest,
state.card_bound[0] if state.card_bound else "")}
def _row_folder(row: TuiRow) -> Path:
+4 -6
View File
@@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, NamedTuple
from installer.cards import card_bound
from installer.choices import available_choices, core_files, emulator_names
from installer.datadirs import select_data_directories
from installer.destination import dest_drive, on_its_card, shown_bios_folder
from installer.destination import dest_drive, shown_bios_folder
from installer.embedded import CARD_PLATFORMS
from installer.frontend_folders import save_directory_for, save_where_words
from installer.games import GAMES_REASONS
@@ -384,11 +384,9 @@ def _tui_card_bound(state: TuiState) -> tuple[str, str] | None:
def _on_its_card(state: TuiState) -> bool:
"""Whether the BIOS folder is on the SD card of the setup it is for, a
system that reads that card alone: room is made there, another folder
being one it never reads."""
if state.dest is None:
return False
return on_its_card(state.platform, state.dest,
state.card_bound[0] if state.card_bound else "")
being one it never reads. Read with the folder facts at the end of the
check, so every frame of the plan and the result shows the same rows."""
return state.dest is not None and bool(state.facts.get("on_card"))
def _dest_card(state: TuiState) -> Path | None:
+29 -4
View File
@@ -9237,6 +9237,7 @@ class LineModeAndScreenDecideAlike(_LineModeFindings, _OutsideTextFindings,
state = checked_state({"free": 1024, "writable": True, "cores": []})
state.dest = onion / "BIOS"
install._DETECTED_OS[("retroarch", state.dest)] = "Onion"
state.facts = install._tui_folder_facts(state)
plan = " ".join(" ".join(install.tui_view(state, 120, 40)).split())
menu = text[:text.index("Enter)")]
self.assertIn("Not enough free space: 4.0 KB needed, 1.0 KB free. Free some space "
@@ -9815,6 +9816,7 @@ class PacksWordingAndDocs(unittest.TestCase):
state.dest = onion / "BIOS"
with mock.patch.object(install, "_mounted_cards", return_value=[onion]), \
mock.patch.dict(install._DETECTED_OS, {("retroarch", onion / "BIOS"): "Onion"}):
state.facts = {**install._tui_folder_facts(state), "free": 1024}
plan = " ".join(install.tui_view(state, 120, 40))
self.assertIn("Free some space on the card first.", plan)
rows = install.tui_rows(state)
@@ -10801,12 +10803,13 @@ class CardNamesAndHelp(_CardFixtures, unittest.TestCase):
# a list or a pack that records some axes only.
def test_a_card_plan_offers_one_remedy_first(self):
for facts, locked in (({"free": 50 * 1024 ** 3, "writable": False, "cores": []}, True),
({"free": 10, "writable": True, "cores": []}, False)):
for facts, locked in (({"free": 50 * 1024 ** 3, "writable": False, "cores": [],
"on_card": True}, True),
({"free": 10, "writable": True, "cores": [], "on_card": True},
False)):
with self.subTest(locked=locked):
state = checked_state(facts)
with mock.patch.object(install, "_on_its_card", return_value=True), \
mock.patch.object(install, "_on_read_only_mount", return_value=locked):
with mock.patch.object(install, "_on_read_only_mount", return_value=locked):
rows = install.tui_rows(state)
text = " ".join(" ".join(install.tui_view(state, 80, 24)).split())
effects = install.tui_update(state, Key("enter"))
@@ -10815,6 +10818,28 @@ class CardNamesAndHelp(_CardFixtures, unittest.TestCase):
self.assertNotIn("choose another one", text)
self.assertEqual(effects, [("run", "check")])
def test_a_card_pulled_out_leaves_the_plan_rows_in_place(self):
"""The plan read the mounted drives on every frame: a card pulled
out while the plan was open moved Check again from under the
focus, and Enter chose another folder."""
card = self.root / "media" / "ONION"
make_card(card, "Onion")
facts = {"free": 10, "writable": True, "cores": []}
state = checked_state(facts)
state.platform, state.card_bound = "retroarch", ("Onion", "BIOS")
state.dest = card / "BIOS"
with mock.patch.object(install, "_mounted_cards", return_value=[card]):
state.facts = {**install._tui_folder_facts(state), "free": 10}
self.assertTrue(state.facts["on_card"])
before = [row.action for row in install.tui_rows(state)]
self.assertEqual(before[0], "recheck")
with mock.patch.object(install, "_mounted_cards", return_value=[]) as scan, \
mock.patch.object(install, "_on_read_only_mount", return_value=False):
install.tui_view(state, 80, 24)
after = [row.action for row in install.tui_rows(state)]
self.assertEqual(scan.call_count, 0)
self.assertEqual(after, before)
def test_options_offer_no_downloads_when_nothing_is_downloaded(self):
"""Parallel downloads offered for an install from a pack."""
state = checked_state()