fix: check the pack's space before its dry run

This commit is contained in:
Abdessamad Derraz committed 2026-11-24 03:39:00 +01:00
1 parent dec7d4bc05
commit efd168dc47
6 files changed
+875 -836

No files matched your search

+1 -1
View File
@@ -16,7 +16,7 @@
# and Invoke-WebRequest throws on a cut transfer before the hash is read:
# the site's build rewrites this line there (scripts/sitebootstrap.py).
$mismatchAdvice = "The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
$defaultInstallSha256 = "8f0f6c89137204a0616984f4d083786e2f23a66b48cb3446a77712d92ebeba17"
$defaultInstallSha256 = "b963351f25c3f1b6ada8e5b6b391a3471f1e72cde6cc5af358518b5a437d71c8"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
$maximumInstallerBytes = 8MB
+828 -817
View File
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -23,7 +23,7 @@ DEFAULT_INSTALL_URL="https://raw.githubusercontent.com/Abdess/retrobios/main/ins
# curl or wget stop on a cut transfer before the hash is read: the site's
# build rewrites this line there (scripts/sitebootstrap.py).
MISMATCH_ADVICE="The download was most likely cut short: try again. Within minutes of an update of this project the two files can come from caches of different ages. Waiting five minutes settles that."
DEFAULT_INSTALL_SHA256="8f0f6c89137204a0616984f4d083786e2f23a66b48cb3446a77712d92ebeba17"
DEFAULT_INSTALL_SHA256="b963351f25c3f1b6ada8e5b6b391a3471f1e72cde6cc5af358518b5a437d71c8"
# The pin above refuses any changed byte: this cap only stops a body that
# cannot be the installer (a sign-in portal's page) before it is hashed.
MAX_INSTALLER_BYTES=8388608
+8 -8
View File
@@ -27,8 +27,8 @@
{
"dest": "roms/ports/retrobios/install.py",
"repo_path": "install.py",
"size": 1501295,
"sha256": "8f0f6c89137204a0616984f4d083786e2f23a66b48cb3446a77712d92ebeba17",
"size": 1494877,
"sha256": "b963351f25c3f1b6ada8e5b6b391a3471f1e72cde6cc5af358518b5a437d71c8",
"executable": false
},
{
@@ -71,8 +71,8 @@
"muos": {
"archive": {
"dest": "ARCHIVE/RetroBIOS.muxapp",
"size": 1554920,
"sha256": "c2f3297e7cb95e6d8d109a4c519fb036f2053ce48bac6b33173743cf0e5f5f61"
"size": 1548502,
"sha256": "6afed8627e633cc6ef5d7eb2054684929ff917ebff8143a8d87307ec5587daad"
},
"members": [
{
@@ -92,8 +92,8 @@
{
"name": "RetroBIOS/install.py",
"repo_path": "install.py",
"size": 1501295,
"sha256": "8f0f6c89137204a0616984f4d083786e2f23a66b48cb3446a77712d92ebeba17",
"size": 1494877,
"sha256": "b963351f25c3f1b6ada8e5b6b391a3471f1e72cde6cc5af358518b5a437d71c8",
"executable": false
},
{
@@ -166,8 +166,8 @@
{
"dest": ".config/modules/retrobios/install.py",
"repo_path": "install.py",
"size": 1501295,
"sha256": "8f0f6c89137204a0616984f4d083786e2f23a66b48cb3446a77712d92ebeba17",
"size": 1494877,
"sha256": "b963351f25c3f1b6ada8e5b6b391a3471f1e72cde6cc5af358518b5a437d71c8",
"executable": false
},
{
+22 -9
View File
@@ -35,8 +35,10 @@ from installer.pack_source import (
part_marker_name,
)
from installer.paths import shown_path
from installer.plan_words import space_remedy
from installer.platforms import PLATFORM_NAMES, TARGET_PLATFORMS, display_name
from installer.safe_replace import BACKUP_DIR
from installer.space import space_shortfall
from installer.text import _plural, format_size, screen_text
if TYPE_CHECKING:
@@ -654,6 +656,22 @@ def _pack_refused(plat: str, path: Path, words: str, code: int,
return code
def _pack_space_refused(plat: str, path: Path, shortfall: tuple[int, int],
members: dict[str, tuple[str, int]]) -> int:
"""No pack for a drive that cannot hold it, refused as a run is for
space (a no_space event and the shared remedy). The dry run checks too,
so the plan never offers a pack the run then refuses to write."""
needed, free = shortfall
EVENTS.emit("no_space", platform=plat, folder=str(path.parent), bytes_needed=needed,
bytes_free=free)
code = _pack_refused(plat, path, f"the drive holding {shown_path(path.parent)} has "
f"{format_size(free)} free, and making the pack needs "
f"{format_size(needed)}", 2, members)
remedy = space_remedy(needed - free, plat, None, commands=False)
print(" " + "\n ".join(remedy), file=sys.stderr)
return code
def pack_parts_words(count: int, limit: int | None, fat: bool) -> str:
"""How the pack is written, in one line: whole, or in parts and why."""
if count == 1:
@@ -725,6 +743,10 @@ def run_pack(args: argparse.Namespace, plat: str, manifest: dict, files: list[di
how = pack_parts_words(count, limit, fat and limit == FAT_PART_BYTES)
if count > 1:
print(f" {how}")
needed = pack_space_bytes(total, pack_bound(len(body), planned), data_dirs)
shortfall = space_shortfall(path.parent, needed)
if shortfall is not None:
return _pack_space_refused(plat, path, shortfall, members)
if args.dry_run:
for name in sorted(members):
detail(f" {screen_text(name)} ({format_size(members[name][1])})")
@@ -732,15 +754,6 @@ def run_pack(args: argparse.Namespace, plat: str, manifest: dict, files: list[di
print(" --verbose lists the files.")
_pack_event(plat, path, members, finals, "planned", how)
return 0
needed = pack_space_bytes(total, pack_bound(len(body), planned), data_dirs)
try:
free = shutil.disk_usage(path.parent).free
except OSError:
free = needed
if free < needed:
return _pack_refused(plat, path, f"the drive holding {shown_path(path.parent)} has "
f"{format_size(free)} free, and making the pack needs "
f"{format_size(needed)}", 2, members)
staging = Path(tempfile.mkdtemp(prefix=f".{path.name}.", suffix=".staging",
dir=str(path.parent)))
try:
+15
View File
@@ -578,8 +578,23 @@ class TheSpaceCountsTheTreeArchive(Repository):
script=str(REPO_ROOT / "install.py")))
self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr)
self.assertIn("has 10.0 MB free", proc.stderr)
self.assertIn("or run it again and choose another folder.", proc.stderr)
self.assertEqual(self.packs(), [])
def test_the_dry_run_refuses_what_the_run_would(self):
"""The screen offered Make the pack from a dry run that never read
the free space, and the run then refused it."""
proc = self.run_installer("--pack", f"{self.out}{os.sep}", "--dry-run", "--events",
code=SPACE_CHILD.format(script=str(REPO_ROOT / "install.py")))
self.assertEqual(proc.returncode, 2, proc.stdout + proc.stderr)
events = [json.loads(line) for line in proc.stdout.splitlines()]
space = next(event for event in events if event["event"] == "no_space")
self.assertEqual(space["bytes_free"], 10 * 1024 * 1024)
self.assertGreater(space["bytes_needed"], space["bytes_free"])
pack = next(event for event in events if event["event"] == "pack")
self.assertEqual(pack["status"], "failed")
self.assertIn("has 10.0 MB free", pack["message"])
def test_the_largest_archive_counts_once(self):
trees = [{"files": {"a": {}}, "archive_size": 300},
{"files": {"b": {}}, "archive_size": 500}, {"files": {}, "archive_size": 9000}]