Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions make_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_make_game_runtime_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <work>/shaders/bcpack/history.bcph (shaders.parent_path() / "bcpack")
import ttpf_mips
Expand Down