From c888ae81015099e1bf5bfd1ae66b765a6e789fc3 Mon Sep 17 00:00:00 2001 From: Abdessamad Derraz <3028866+Abdess@users.noreply.github.com> Date: Sat, 21 Nov 2026 18:28:45 +0100 Subject: [PATCH] fix: keep stdout to events in a removal --remove and --backups opened the --manifest and --from-pack before the event stream started: the list's platform and the pack name went to stdout ahead of start, and a refusal of the pack came with no event. They are opened inside the action now. --- install.ps1 | 2 +- install.py | 14 ++++++++++++-- install.sh | 2 +- install/launchers/index.json | 16 ++++++++-------- installer/cli.py | 14 ++++++++++++-- tests/test_install_removal.py | 18 ++++++++++++++++++ 6 files changed, 52 insertions(+), 14 deletions(-) diff --git a/install.ps1 b/install.ps1 index 52cf0c9ca..ad2d470c1 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 = "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa" + $defaultInstallSha256 = "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab" # 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 652f5be2d..b76626676 100644 --- a/install.py +++ b/install.py @@ -32149,8 +32149,7 @@ def _main_run() -> None: _main_check_offline(parser, args) install_bounded_opener() if args.remove or args.backups: - _open_local_sources(args) - _run_action(args, run_removal if args.remove else run_backups) + _run_action(args, _with_local_sources(run_removal if args.remove else run_backups)) _main_check_sources(parser, args) _main_dispatch(args) @@ -32231,6 +32230,17 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No f"name): {name}") +def _with_local_sources(action: Callable[[argparse.Namespace], int], + ) -> Callable[[argparse.Namespace], int]: + """action, the list and the pack it was given opened first. Opened + before the action, they said the list's platform on stdout ahead of + start, the first line of --events no JSON.""" + def opened(args: argparse.Namespace) -> int: + _open_local_sources(args) + return action(args) + return opened + + def _run_action(args: argparse.Namespace, action: Callable[[argparse.Namespace], int]) -> NoReturn: """Run an action and exit with its code, its events framed by start and diff --git a/install.sh b/install.sh index b9012e4e0..fca3b5e79 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="ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa" +DEFAULT_INSTALL_SHA256="5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab" # 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 05cdd29c2..adf9ea54c 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": 1465384, - "sha256": "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa", + "size": 1465830, + "sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab", "executable": false }, { @@ -71,8 +71,8 @@ "muos": { "archive": { "dest": "ARCHIVE/RetroBIOS.muxapp", - "size": 1519009, - "sha256": "de8c0baf1dc070332235391e2ea42159337d79eff9adf796cbf2bd8c676b3aa7" + "size": 1519455, + "sha256": "4af67cea311827c3546e9ea72682730c2edc799933d85768ade64c6a2a77f669" }, "members": [ { @@ -92,8 +92,8 @@ { "name": "RetroBIOS/install.py", "repo_path": "install.py", - "size": 1465384, - "sha256": "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa", + "size": 1465830, + "sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab", "executable": false }, { @@ -166,8 +166,8 @@ { "dest": ".config/modules/retrobios/install.py", "repo_path": "install.py", - "size": 1465384, - "sha256": "ed45f61685e87ea272a58178321d4fefb4421e556404e14e36381b023cf191fa", + "size": 1465830, + "sha256": "5b0e9b51ce568e6973c43ae4868c831c758911b258796d44475265058ba327ab", "executable": false }, { diff --git a/installer/cli.py b/installer/cli.py index 2f8312dbd..acd32e48f 100644 --- a/installer/cli.py +++ b/installer/cli.py @@ -349,8 +349,7 @@ def _main_run() -> None: _main_check_offline(parser, args) install_bounded_opener() if args.remove or args.backups: - _open_local_sources(args) - _run_action(args, run_removal if args.remove else run_backups) + _run_action(args, _with_local_sources(run_removal if args.remove else run_backups)) _main_check_sources(parser, args) _main_dispatch(args) @@ -431,6 +430,17 @@ def _check_pack(parser: argparse.ArgumentParser, args: argparse.Namespace) -> No f"name): {name}") +def _with_local_sources(action: Callable[[argparse.Namespace], int], + ) -> Callable[[argparse.Namespace], int]: + """action, the list and the pack it was given opened first. Opened + before the action, they said the list's platform on stdout ahead of + start, the first line of --events no JSON.""" + def opened(args: argparse.Namespace) -> int: + _open_local_sources(args) + return action(args) + return opened + + def _run_action(args: argparse.Namespace, action: Callable[[argparse.Namespace], int]) -> NoReturn: """Run an action and exit with its code, its events framed by start and diff --git a/tests/test_install_removal.py b/tests/test_install_removal.py index bf74ec498..64f9bb96c 100644 --- a/tests/test_install_removal.py +++ b/tests/test_install_removal.py @@ -335,6 +335,24 @@ class Events(unittest.TestCase): ["event", *install.EVENT_KEYS[event["event"]]])) + def test_a_list_given_as_a_file_keeps_stdout_to_events(self): + """The list's platform was said on stdout before start: a reader + of the stream got a first line that is not JSON.""" + with SharedRepository() as repo: + repo.install_both() + listed = repo.root / "install" / "retroarch.json" + # The command without --platform: the list names it. + python, script = repo.command()[:2] + proc = subprocess.run( + [python, script, "--dest", str(repo.dest), "--remove", "--dry-run", + "--events", "--manifest", str(listed)], + env=repo.env(), capture_output=True, text=True, timeout=60, check=False, + stdin=subprocess.DEVNULL) + self.assertEqual(proc.returncode, 0, proc.stderr) + kinds = [json.loads(line)["event"] for line in proc.stdout.splitlines()] + self.assertEqual(kinds, ["start", "removal_plan", "end"]) + self.assertIn("File list:", proc.stderr) + class DeleteABackup(unittest.TestCase): def test_only_a_backup_folder_and_only_with_a_yes(self): with SharedRepository() as repo: