make_game: preflight counts an asset export that stopped part-way

#905 leaves the assets stage's 300 GB out of the space check only when the
export finished (xma.done). A run stopped after the models, textures and most
texture pools still asked for the full 330 GB, so a drive that already held
270 GB of that export and had 205 GB free refused to resume, although the
stage skips every finished step.

When the free space is short and the assets stage is selected, preflight now
subtracts the whole GB already under <work>/assets (capped at the 300 GB
estimate) and logs it. assets_bytes_on_disk() is one os.scandir walk that
does not follow links; it runs only in that short-on-space case. A fresh
folder still needs the full amount, and --wav still counts the whole
estimate, as in #905.
This commit is contained in:
Leonardo Guimaraes
2026-11-22 15:17:11 -03:00
parent ec8ec4c9a4
commit d49b8e78e6
2 changed files with 89 additions and 0 deletions

View File

@ -385,6 +385,27 @@ def assets_exported(work: str) -> bool:
return not (shutil.which("ffmpeg") and pending_xma(os.path.join(audio, "xma")))
def assets_bytes_on_disk(work: str) -> int:
"""Bytes already under <work>/assets: the part of the assets stage's space that a stopped export has used and
a rerun won't write again, since the stage skips every step whose manifest or marker is there. One os.scandir
walk; on Windows the sizes come with the directory listing, so no file is opened. Links are not followed."""
total, stack = 0, [os.path.join(work, "assets")]
while stack:
try:
with os.scandir(stack.pop()) as it:
for e in it:
try:
if e.is_dir(follow_symlinks=False):
stack.append(e.path)
elif e.is_file(follow_symlinks=False):
total += e.stat(follow_symlinks=False).st_size
except OSError:
continue
except OSError: # no assets folder yet, or one that can't be listed: count nothing for it
continue
return total
def pipeline_check_prerequisite(runtime_selected: bool = False) -> str:
"""Why the pipelines stage can't run yet. Kept here so preflight can fail before a long shader build;
pipelines() prints its own, more detailed message when the stage is reached. On Windows the runtime stage
@ -456,6 +477,15 @@ def preflight(stages: list, work: str, wav: bool = False, runtime_build: str | N
if free_gb < need_gb and need.get("shaders") and shader_outputs_reusable(work, emulate, keep_emulated, fallbacks):
log(f"preflight: the shaders in {work} can be reused; not counting their {need['shaders']} GB")
need_gb -= need["shaders"]
# An export stopped part-way (no xma.done yet) has already put some of the 300 GB on the drive, and the rerun
# skips those steps. Only walked when the space is short, so a build with room to spare reads no folder.
# --wav still counts the whole estimate, as above: the WAV decode writes several times the Ogg Opus size and has
# no marker, so what is on disk says nothing about what it will still write.
if free_gb < need_gb and need.get("assets") and not wav:
done_gb = min(assets_bytes_on_disk(work) // 2**30, need["assets"])
if done_gb:
log(f"preflight: {done_gb} GB of a stopped asset export is already in {work}; not counting it again")
need_gb -= done_gb
if free_gb < need_gb:
fail(f"{free_gb:.0f} GB free on the drive of {work}, about {need_gb} GB is needed. "
"Free some space or choose another drive with --work.")

View File

@ -821,6 +821,65 @@ class PreflightExportedAssetsSpaceTest(PreflightTestBase):
self.write_markers(work)
self.assert_fails(self.run_preflight, work, free_gb=220, wav=True, match="about 330 GB is needed")
# A stopped export: models, textures and most pools on disk, no xma.done yet.
def run_partial(self, work, free_gb, on_disk_gb, **kwargs):
with mock.patch("make_game.assets_bytes_on_disk", return_value=on_disk_gb * 2**30) as walk:
self.run_preflight(work, free_gb, **kwargs)
return walk
def test_stopped_export_counts_what_is_already_on_disk(self):
# The case this was found on: 270 GB already exported, 205 GB free, refused for 330 GB.
with tempfile.TemporaryDirectory() as work:
self.write_markers(work, xma=None)
self.run_partial(work, free_gb=205, on_disk_gb=270) # 30 + 300 - 270 = 60 GB
def test_stopped_export_still_needs_what_is_left(self):
with tempfile.TemporaryDirectory() as work:
self.write_markers(work, xma=None)
err = self.assert_fails(self.run_partial, work, free_gb=205, on_disk_gb=50,
match="about 280 GB is needed")
self.assertIn("205 GB free", err)
def test_more_on_disk_than_the_estimate_leaves_the_shader_space(self):
with tempfile.TemporaryDirectory() as work:
self.write_markers(work, xma=None)
self.assert_fails(self.run_partial, work, free_gb=20, on_disk_gb=400, match="about 30 GB is needed")
def test_assets_folder_is_not_walked_when_there_is_room(self):
with tempfile.TemporaryDirectory() as work:
walk = self.run_partial(work, free_gb=500, on_disk_gb=270)
walk.assert_not_called()
def test_wav_still_counts_the_whole_asset_space_for_a_stopped_export(self):
with tempfile.TemporaryDirectory() as work:
self.write_markers(work, xma=None)
self.assert_fails(self.run_partial, work, free_gb=205, on_disk_gb=270, wav=True,
match="about 330 GB is needed")
def test_assets_bytes_on_disk_sums_every_file_below_assets(self):
with tempfile.TemporaryDirectory() as work:
self.assertEqual(make_game.assets_bytes_on_disk(work), 0) # no assets folder yet
for rel, size in (("levels/models/a.obj", 100), ("levels/manifest.json", 7),
("ttpf/pool/b.dds", 4096), ("top.bin", 1)):
path = os.path.join(work, "assets", *rel.split("/"))
os.makedirs(os.path.dirname(path), exist_ok=True)
with open(path, "wb") as f:
f.write(b"\0" * size)
with open(os.path.join(work, "outside.bin"), "wb") as f: # not under assets: not counted
f.write(b"\0" * 999)
self.assertEqual(make_game.assets_bytes_on_disk(work), 100 + 7 + 4096 + 1)
def test_assets_bytes_on_disk_does_not_follow_a_linked_folder(self):
with tempfile.TemporaryDirectory() as work, tempfile.TemporaryDirectory() as elsewhere:
with open(os.path.join(elsewhere, "big.bin"), "wb") as f:
f.write(b"\0" * 5000)
os.makedirs(os.path.join(work, "assets"))
try:
os.symlink(elsewhere, os.path.join(work, "assets", "link"), target_is_directory=True)
except (OSError, NotImplementedError):
self.skipTest("symbolic links are not available here")
self.assertEqual(make_game.assets_bytes_on_disk(work), 0)
if __name__ == "__main__":
unittest.main()