Repository navigation
ADFA-5105: guard free space before a destructive run - #391
Merged
Merged
Conversation
…— and only two of them gated anything. The wizard install, reinstall, restore and reset had no check: a wipe followed by an extract that runs out of disk left an unbootable rootfs. One reader, one margin, on the filesystem actually written to. Core (pure JVM, unit-tested): - storage/StorageGuard: the single rule. Hybrid margin max(2 GiB floor, 10%); FITS / DOES_NOT_FIT / UNKNOWN verdict; shortfall; overflow-safe. - storage/SpaceEstimate: compressed -> uncompressed estimate (restore only). Android: - storage/StorageProbe: the one free-space reader, on getFilesDir() (where the rootfs is written) — not /data. Null on failure so destructive callers refuse. - storage/FreeSpacePreflight: reads free + asks the rule; proceeds only on FITS. Gated the destructive routes before the wipe (UNKNOWN refuses, fail-safe): - InstallService.runPipeline / runResetPipeline (reinstall, reset, fresh install). - DeepOpService.runRestore (restore). The rootfs "needed" is the UNCOMPRESSED size from RootfsCatalog.installedBytes (measured, published by ADFA-5110 as latest_*.installed and captured into rootfs_sizes.csv's installed_bytes column; measured constants as the offline fallback). Restore estimates from the backup archive. Consolidated the rest onto the same reader/rule: - PlannerController and SyncStateViewModel now use StorageGuard/StorageProbe instead of a second -5 GB copy. - The advisory picker labels (Maps, ZIM x3, Kolibri x3) read StorageProbe, not a per-screen StatFs. No hand-rolled `new StatFs(...)` remains outside StorageProbe. - Dropped the stale "5GB buffer" wording from the two error strings. Verification: unit tests (StorageGuardTest, SpaceEstimateTest) + javalang/XML. End-to-end refusal-before-wipe needs a device (StatFs + real rm/extract).
Post-review fixes: - Peak, not final footprint: the destructive install gate runs before the download, and the compressed .tar.gz and the uncompressed tree coexist during extraction, so the "needed" is the peak. RootfsCatalog.peakInstallBytes() (uncompressed + compressed); InstallService uses it. Full arm64 is ~7.4 GiB peak vs ~4.75 GiB final — the old figure could pass an install that then ran out of disk mid-extract. - Advisory matches the hard gate: PlannerController sizes the OS by its uncompressed footprint (the legend, and the "fits" decision on the same peak), instead of the compressed download — so it no longer says "fits" then the install refuses. - Restore estimate: SpaceEstimate factor 2.3 -> 2.2 (rootfs-shaped archives expand at most ~1.80x across tiers; 2.2x plus the StorageGuard margin keeps it safe). This factor now only backs restore, since the rootfs uses the measured size; a principled replacement (read the archive's real size) is a follow-up. - Disk hygiene: delete the downloaded .tar.gz on a failed extract too, not only on success (a failure used to keep ~2-3 GB until the next attempt). SpaceEstimateTest updated for 2.2x.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sixteen hand-rolled free-space readers, four APIs, two magic margins and only two of them gated anything. The wizard install, reinstall, restore and reset had no check: a wipe followed by an extract that runs out of disk left an unbootable rootfs. One reader, one margin, on the filesystem actually written to.
Core (pure JVM, unit-tested):
Android:
Gated the destructive routes before the wipe (UNKNOWN refuses, fail-safe):
Consolidated the rest onto the same reader/rule:
new StatFs(...)remains outside StorageProbe.Verification: unit tests (StorageGuardTest, SpaceEstimateTest) + javalang/XML. End-to-end refusal-before-wipe needs a device (StatFs + real rm/extract).