From 0fa9a51ab0f5aaecdf58924e6281132cc1c4db3d Mon Sep 17 00:00:00 2001 From: aznohonza Date: Mon, 30 Nov 2026 22:24:34 +0100 Subject: [PATCH] make_game: keep recovery copies until an install succeeds install_runtime() removed every .runtime-staging-* folder before it started, including the folder an IncompleteRollback kept as the only copies of the previous runtime. If the retry also failed, those copies were already gone. Clean the stale folders only after a successful publish, so a failed retry leaves the recovery folder in place. RT-INSTALL-KEEP-RECOVERY. --- make_game.py | 12 +++++++----- tests/test_make_game_runtime_staging.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/make_game.py b/make_game.py index 31a24a8f20..1a97a50225 100644 --- a/make_game.py +++ b/make_game.py @@ -2962,12 +2962,9 @@ def install_runtime(game: str, out: str, artifacts: list, work: str | None = Non it published (publish(): all files or none). A failure while copying (disk full, an interrupt) or while publishing (a destination file held open) leaves the previous install untouched and no staging folder behind, instead of a new gta6rt.exe next to an old gta6rt_tls_host.dll. The one exception is a rollback that is itself - blocked (IncompleteRollback): the staging folder, which then holds the old files, is kept for recovery.""" + blocked (IncompleteRollback): the staging folder, which then holds the old files, is kept for recovery until a + later install succeeds.""" os.makedirs(out, exist_ok=True) - # A run that kept its staging folder (IncompleteRollback), or that could not delete the old gta6rt.exe it moved - # there because the game was still running, leaves one behind. - for stale in glob.glob(os.path.join(glob.escape(out), ".runtime-staging-*")): - shutil.rmtree(stale, ignore_errors=True) stage = tempfile.mkdtemp(prefix=".runtime-staging-", dir=out) try: staged = [] @@ -3003,6 +3000,11 @@ def install_runtime(game: str, out: str, artifacts: list, work: str | None = Non shutil.rmtree(stage, ignore_errors=True) raise shutil.rmtree(stage, ignore_errors=True) + # Only now: a folder kept by an earlier IncompleteRollback holds the only copies of the previous runtime files, + # so a retry that fails must leave it in place (the previous attempt deleted it before starting). A run that + # could not delete the old gta6rt.exe it moved there, because the game was still running, leaves one too. + for stale in glob.glob(os.path.join(glob.escape(out), ".runtime-staging-*")): + shutil.rmtree(stale, ignore_errors=True) class IncompleteRollback(OSError): diff --git a/tests/test_make_game_runtime_staging.py b/tests/test_make_game_runtime_staging.py index 74b2998f06..f1e0e6c653 100644 --- a/tests/test_make_game_runtime_staging.py +++ b/tests/test_make_game_runtime_staging.py @@ -193,6 +193,18 @@ def test_stale_staging_folders_are_removed_by_the_next_install(self): install(self.game, self.out, self.artifacts) self.assertFalse(os.path.exists(stale)) + def test_failed_retry_keeps_the_previous_recovery_folder(self): + # An IncompleteRollback leaves the old copies in its staging folder, which is then the only copy of the + # previous runtime. A retry that fails must not have deleted it before it started. + stale = os.path.join(self.out, ".runtime-staging-kept-by-a-blocked-rollback") + os.makedirs(stale) + with open(os.path.join(stale, "gta6rt.exe.old"), "wb") as f: + f.write(b"old") + with patch.object(make_game.shutil, "copy2", side_effect=OSError(28, "No space left on device")): + with self.assertRaises(OSError): + install(self.game, self.out, self.artifacts) + self.assertEqual(read(os.path.join(stale, "gta6rt.exe.old")), b"old") + def test_bcpack_history_is_built_where_the_runtime_reads_it(self): # runtime/shims/dstorage.cpp reads /shaders/bcpack/history.bcph (shaders.parent_path() / "bcpack") import ttpf_mips