mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-20 14:39:58 -04:00
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:
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user