Ask the disk for room before a download or an unpack starts.

A disk that filled in the middle ended a download after four tries with an error that named no cause, and an unpack
with half a folder. The rest of a download, the build tools with their unpacked size, an update's archive and a
mod's zip are now measured against the free space first, and the refusal says how much is needed and how much is
free; a disk that fills during a download is named as full at once.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
chrg6
2026-11-12 22:19:28 -05:00
parent fe041188f5
commit d0e6cd695e
6 changed files with 156 additions and 4 deletions

View File

@@ -60,7 +60,8 @@ def runtime_id(layout):
def safe_extract(zip_path, dest):
"""Unpack a zip into dest, refusing absolute names and names that climb out of it."""
"""Unpack a zip into dest, refusing absolute names and names that climb out of it, and, before anything is
written, a zip whose files do not fit the disk (net.space_problem)."""
dest = Path(dest)
root = dest.resolve()
with zipfile.ZipFile(zip_path) as z:
@@ -71,6 +72,10 @@ def safe_extract(zip_path, dest):
target = (dest / name).resolve()
if target != root and root not in target.parents:
raise UpdateError(f'{Path(zip_path).name}: unsafe path {info.filename}')
full = net.space_problem(dest, sum(info.file_size for info in z.infolist()),
f'the files of {Path(zip_path).name}')
if full:
raise UpdateError(full)
z.extractall(dest)