diff --git a/install.ps1 b/install.ps1 index ad2d470c1..c48da54ee 100644 --- a/install.ps1 +++ b/install.ps1 @@ -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 = "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab" + $defaultInstallSha256 = "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854" # 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 diff --git a/install.py b/install.py index b76626676..891996de1 100644 --- a/install.py +++ b/install.py @@ -8904,12 +8904,17 @@ def load_targets(plat: str, attempts: int = MAX_RETRIES, raise _download_failure(plat, url, remote, exc, fatal=0) from exc +def targets_file_words(failure: ListProblem) -> str: + """Why the board list beside --manifest cannot be used, in one clause.""" + state = "cannot be read" if failure.code == "unreadable" else "is not valid" + return f"the target list {failure.where} {state}: {failure.words}" + + def targets_failure_lines(failure: ListProblem) -> list[str]: """What line mode prints of a board list it could not have.""" plat, code, words, where = failure.plat, failure.code, failure.words, failure.where if failure.source == "file": - state = "cannot be read" if code == "unreadable" else "is not valid" - return [f" Error: the target list {where} {state}: {words}"] + return [f" Error: {targets_file_words(failure)}"] if code == "offline": return [f"Error: --target needs the {display_name(plat)} board list ({words}). Put " f"install/targets/{plat}.json beside the --manifest file, or go online."] @@ -19480,13 +19485,18 @@ def _listed_paths(folder: Path) -> list[Path]: def _pack_targets(plat: str) -> dict | None: """The cores per board the pack carries, as a pack built by the repository does: the list at hand offline, else the one fetched. None - for a platform that publishes none, or a list that cannot be read.""" + for a platform that publishes none, or a list the network did not + bring. ListFailure for a list this run was given and cannot use.""" if plat not in TARGET_PLATFORMS: return None if LOCAL.offline: - return local_targets(plat) - with contextlib.redirect_stderr(io.StringIO()): - return fetch_targets(plat) + return held_targets(plat) + try: + return load_targets(plat) + except ListFailure as stopped: + if stopped.problem.fatal: + raise + return None def _pack_event(plat: str, path: Path, members: dict[str, tuple[str, int]], @@ -19545,8 +19555,15 @@ def run_pack(args: argparse.Namespace, plat: str, manifest: dict, files: list[di members, rows, sources = pack_layout(files, data_dirs) if not members: return _pack_refused(plat, path, "the choice keeps no file to put in a pack", 2) + try: + targets = _pack_targets(plat) + except ListFailure as stopped: + failure = stopped.problem + words = (targets_file_words(failure) if failure.source == "file" else + f"the board list for {display} could not be read: {failure.words}") + return _pack_refused(plat, path, words, failure.fatal, members) body = pack_manifest(plat, pack_install_list(manifest, files, omitted, data_dirs), rows, - _pack_targets(plat)) + targets) planned = [PackMember(name, sha1, size, Path()) for name, (sha1, size) in sorted(members.items())] fat = fat32_drive(path.parent) @@ -23210,14 +23227,15 @@ def _check_run_target(run: _InstallRun) -> None: if args.target and by_record(args) and len(platforms) == 1: # The screen's runs carry the record's options as typed ones. plat = platforms[0][0] - if LOCAL.offline and local_targets(plat) is None and plat in TARGET_PLATFORMS: - drop_recorded(args, plat, "--target", "the board list needs the internet") + try: + known = load_targets(plat) + except ListFailure as stopped: + drop_recorded(args, plat, "--target", "the board list needs the internet" + if stopped.problem.code == "offline" + else "the board list could not be read") else: - with contextlib.redirect_stderr(io.StringIO()): - known = fetch_targets(plat) - if known is None or args.target not in known: - drop_recorded(args, plat, "--target", "the board list does not name it" - if known is not None else "the board list could not be read") + if args.target not in known: + drop_recorded(args, plat, "--target", "the board list does not name it") if args.target: for plat_name, _bios_path in platforms: targets = fetch_targets(plat_name) diff --git a/install.sh b/install.sh index fca3b5e79..6229cb5ad 100755 --- a/install.sh +++ b/install.sh @@ -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="5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab" +DEFAULT_INSTALL_SHA256="bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854" # 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 diff --git a/install/launchers/index.json b/install/launchers/index.json index adf9ea54c..8b0f56096 100644 --- a/install/launchers/index.json +++ b/install/launchers/index.json @@ -27,8 +27,8 @@ { "dest": "roms/ports/retrobios/install.py", "repo_path": "install.py", - "size": 1465830, - "sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab", + "size": 1461669, + "sha256": "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1519455, - "sha256": "4af67cea311827c3546e9ea72682730c2edc799933d85768ade64c6a2a77f669" + "size": 1515294, + "sha256": "6f00452c27a790eb8c6f38d1d30dddac00dd666f4b7fdf214706a1088f268eb5" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1465830, - "sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab", + "size": 1461669, + "sha256": "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1465830, - "sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab", + "size": 1461669, + "sha256": "bbb7e293a1afa813beab344ce32182ac447a31324e7164fb7f09b6093bba4854", "executable": false }, { diff --git a/installer/lists.py b/installer/lists.py index 03dc6544d..c92c439bc 100644 --- a/installer/lists.py +++ b/installer/lists.py @@ -310,12 +310,17 @@ def load_targets(plat: str, attempts: int = MAX_RETRIES, raise _download_failure(plat, url, remote, exc, fatal=0) from exc +def targets_file_words(failure: ListProblem) -> str: + """Why the board list beside --manifest cannot be used, in one clause.""" + state = "cannot be read" if failure.code == "unreadable" else "is not valid" + return f"the target list {failure.where} {state}: {failure.words}" + + def targets_failure_lines(failure: ListProblem) -> list[str]: """What line mode prints of a board list it could not have.""" plat, code, words, where = failure.plat, failure.code, failure.words, failure.where if failure.source == "file": - state = "cannot be read" if code == "unreadable" else "is not valid" - return [f" Error: the target list {where} {state}: {words}"] + return [f" Error: {targets_file_words(failure)}"] if code == "offline": return [f"Error: --target needs the {display_name(plat)} board list ({words}). Put " f"install/targets/{plat}.json beside the --manifest file, or go online."] diff --git a/installer/pack.py b/installer/pack.py index c2f9bb774..b9b66cdb8 100644 --- a/installer/pack.py +++ b/installer/pack.py @@ -2,9 +2,7 @@ from __future__ import annotations import argparse -import contextlib import hashlib -import io import json import os import shutil @@ -26,7 +24,7 @@ from installer.events import EVENTS from installer.filesystems import fat32_drive from installer.from_folders import plan_local_copies from installer.host_fs import DRIVE_FULL, _drive_full, _is_dir, _stop -from installer.lists import fetch_targets, local_targets +from installer.lists import ListFailure, held_targets, load_targets, targets_file_words from installer.offline import LOCAL from installer.pack_source import ( _PART_FILE, @@ -627,13 +625,18 @@ def _listed_paths(folder: Path) -> list[Path]: def _pack_targets(plat: str) -> dict | None: """The cores per board the pack carries, as a pack built by the repository does: the list at hand offline, else the one fetched. None - for a platform that publishes none, or a list that cannot be read.""" + for a platform that publishes none, or a list the network did not + bring. ListFailure for a list this run was given and cannot use.""" if plat not in TARGET_PLATFORMS: return None if LOCAL.offline: - return local_targets(plat) - with contextlib.redirect_stderr(io.StringIO()): - return fetch_targets(plat) + return held_targets(plat) + try: + return load_targets(plat) + except ListFailure as stopped: + if stopped.problem.fatal: + raise + return None def _pack_event(plat: str, path: Path, members: dict[str, tuple[str, int]], @@ -692,8 +695,15 @@ def run_pack(args: argparse.Namespace, plat: str, manifest: dict, files: list[di members, rows, sources = pack_layout(files, data_dirs) if not members: return _pack_refused(plat, path, "the choice keeps no file to put in a pack", 2) + try: + targets = _pack_targets(plat) + except ListFailure as stopped: + failure = stopped.problem + words = (targets_file_words(failure) if failure.source == "file" else + f"the board list for {display} could not be read: {failure.words}") + return _pack_refused(plat, path, words, failure.fatal, members) body = pack_manifest(plat, pack_install_list(manifest, files, omitted, data_dirs), rows, - _pack_targets(plat)) + targets) planned = [PackMember(name, sha1, size, Path()) for name, (sha1, size) in sorted(members.items())] fat = fat32_drive(path.parent) diff --git a/installer/run_setups.py b/installer/run_setups.py index 1957fdd09..de28ab38b 100644 --- a/installer/run_setups.py +++ b/installer/run_setups.py @@ -2,8 +2,6 @@ from __future__ import annotations import argparse -import contextlib -import io import os import sys from pathlib import Path @@ -28,11 +26,11 @@ from installer.line_folder import ( ask_platform_folder, share_words, ) -from installer.lists import fetch_targets, local_targets +from installer.lists import ListFailure, fetch_targets, load_targets from installer.offline import LOCAL from installer.pack import pack_path from installer.pack_source import pack_name_platforms -from installer.platforms import AVAILABLE_PLATFORMS, TARGET_PLATFORMS, _NO_BIOS_FOLDER, display_name, normalize_platform +from installer.platforms import AVAILABLE_PLATFORMS, _NO_BIOS_FOLDER, display_name, normalize_platform from installer.run_files import _output_kind from installer.safe_replace import KEPT from installer.setups import PORTABLE_ONLY, _default_dest, _line_setups, drive_example, found_setups @@ -437,14 +435,15 @@ def _check_run_target(run: _InstallRun) -> None: if args.target and by_record(args) and len(platforms) == 1: # The screen's runs carry the record's options as typed ones. plat = platforms[0][0] - if LOCAL.offline and local_targets(plat) is None and plat in TARGET_PLATFORMS: - drop_recorded(args, plat, "--target", "the board list needs the internet") + try: + known = load_targets(plat) + except ListFailure as stopped: + drop_recorded(args, plat, "--target", "the board list needs the internet" + if stopped.problem.code == "offline" + else "the board list could not be read") else: - with contextlib.redirect_stderr(io.StringIO()): - known = fetch_targets(plat) - if known is None or args.target not in known: - drop_recorded(args, plat, "--target", "the board list does not name it" - if known is not None else "the board list could not be read") + if args.target not in known: + drop_recorded(args, plat, "--target", "the board list does not name it") if args.target: for plat_name, _bios_path in platforms: targets = fetch_targets(plat_name) diff --git a/tests/test_install_journeys.py b/tests/test_install_journeys.py index c3798746e..5e5b389a4 100644 --- a/tests/test_install_journeys.py +++ b/tests/test_install_journeys.py @@ -701,6 +701,25 @@ class RecordReview(unittest.TestCase): # Typed, it is refused as before. self.assertNotEqual(self.run_line(*typed, "--check").returncode, 0) + def test_a_recorded_target_with_an_unreadable_board_list_is_left_out(self): + """The board list beside --manifest could not be read: the run ended + with code 1 and said nothing, its stderr thrown away. The screen's + runs carry the record's options as typed ones.""" + targets = self.repo.site / "install" / "targets" + targets.mkdir() + (targets / "retroarch.json").write_text("{not json") + proc = subprocess.run( + [sys.executable, str(REPO_ROOT / "install.py"), "--platform", "retroarch", + "--dest", str(self.dest), "--system", "nintendo-gba", "--target", "switch", + "--manifest", str(self.repo.site / "install" / "retroarch.json"), + "--yes", "--events"], + env={**self.repo.env, install.TUI_RECORD_ENV: "1"}, capture_output=True, + text=True, timeout=120, check=False, stdin=subprocess.DEVNULL) + self.assertEqual(proc.returncode, 0, proc.stdout + proc.stderr) + self.assertIn("Left out of the recorded choice: --target (the board list could not " + "be read).", proc.stderr) + self.assertEqual(self.dests(proc), ["gba_bios.bin"]) + def test_a_date_no_clock_can_show_is_an_unknown_day(self): if not hasattr(time, "tzset"): self.skipTest("no tzset") diff --git a/tests/test_install_pack.py b/tests/test_install_pack.py index f227d8a0b..426af7871 100644 --- a/tests/test_install_pack.py +++ b/tests/test_install_pack.py @@ -382,6 +382,21 @@ class Events(Repository): self.assertEqual((pack["status"], pack["parts"]), ("failed", [])) self.assertEqual(events[-1], {"event": "end", "code": 1}) + def test_a_board_list_beside_the_manifest_it_cannot_read_is_said(self): + """The run ended with code 1, no pack event and nothing on stderr.""" + (self.served / "install" / "targets").mkdir() + (self.served / "install" / "targets" / "retroarch.json").write_text("{not json") + proc = self.make("--events", "--dry-run", "--manifest", + str(self.served / "install" / "retroarch.json")) + events = [json.loads(line) for line in proc.stdout.splitlines()] + self.assertEqual(proc.returncode, 1) + self.assertIn("targets/retroarch.json is not valid", proc.stderr) + self.assertIn("No pack was written.", proc.stderr) + pack = next(event for event in events if event["event"] == "pack") + self.assertEqual(pack["status"], "failed") + self.assertIn("is not valid", pack["message"]) + self.assertEqual(events[-1], {"event": "end", "code": 1}) + class Refusals(Repository): def test_options_of_this_machine_s_folder_are_refused(self):