fix(storage): remove obsolete build files about three times faster #396
No reviewers
Labels
No labels
area/build
area/install
area/mods
area/saves
area/tooling
area/ui
area/updates
ci: approved
good first issue
gpu/amd
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
platform/linux
platform/steam-deck
platform/windows
priority
critical
priority
high
priority
low
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/LongshotLauncher!396
Loadingβ¦
Reference in a new issue
No description provided.
Delete branch "Jiro113/LongshotLauncher:reclaim-fast-delete"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Removing obsolete launcher files is very slow on Windows: an old extracted RomFS holds about 186,000 files, and the Storage page's cleanup removed them at a few thousand per second at best. This makes the whole cleanup about three times faster on Windows without loosening what it checks.
What
Before removing each reviewed file,
Plan::execute_with_progresscalleddirect(path), which reads the metadata of every folder above the file, then opened the file three times (once for its data, which the antivirus scans).remove_reviewedin src/storage/reclaim.rs), each file is opened withDELETE | FILE_READ_ATTRIBUTES, without following a link at the last part of the path. That handle checks that it is still the reviewed file (identity, size, time) and that the path it was reached at (GetFinalPathNameByHandleW, asfs::canonicalizeasks it during the scan) is the reviewed path, so a link at any level, swapped in before or during the cleanup, stops it. The same handle then deletes the file (FileDispositionInfoExwith POSIX semantics and the read-only attribute ignored, asfs::remove_filedoes;FileDispositionInfoon file systems without them). For a read-only file in the fallback, it reopens the checked file by handle to clear the attribute, and attempts to restore it if deletion fails. Nothing can change between that check and the removal.file_identity(src/storage.rs) opens files with attribute access only, so the review and the scan that runs again before the removal don't open each file for its data either.lstatis cheap there), then the same identity, size and time check andremove_file.Files that another program has open without sharing read access now get an identity and appear in the plan; if that program doesn't allow deletion either, the cleanup stops at that file with "Could not remove ...", as it does for any file it cannot remove.
Nothing changes on screen: the dialog and its progress are the same.
Measurements
Local, Windows 11, debug build, one synthetic extraction of 50,000 small files four folders deep in a temporary folder, cleaned through
scan::plan_for(the review) andPlan::execute(Clean up: the scan again, then the removal); three runs each, same machine, nothing else building (benchmark not committed):c1bc2e00e82392Not measured on a real extraction, and not on Linux (where the removal path is the same as before apart from the per-file reads).
Tests
cargo fmt --checkandcargo clippy --locked --workspace --all-targets -- -D warningspass on Windows.cargo teston Windows: 271 pass, and the same 12 tests fail on main on this PC (e.g.storage::reclaim::preservation::previous_build_review_removes_only_selected_outputs_after_confirmation), sotests/test_launcher_core.pystops there too. Tooling'stest_release.py: 46 pass.π€ Generated with Claude Code
Possibly related, for context:
@review
Recommendation: Request changes. The cached directory check can delete files after their folder has been moved outside the reviewed location. The Windows fallback also cannot remove read-only files on filesystems that reject the extended disposition flags.
The change reduces repeated directory checks and Windows file opens during storage cleanup. It speeds up a synthetic Windows removal benchmark, but weakens the protection against directory changes during cleanup and has an incomplete Windows fallback.
Blocking (1): must change before merging.
src/storage/reclaim.rs:255: A checked directory remains trusted after it is replaced by a link, so file identity no longer confines deletion to the reviewed path. (more on the line) Do: Keep directory handles that prevent or detect replacement while removing their children, or revalidate the path before each removal. Add a test that swaps the folder after the first progress callback.Should fix (1): not blocking, but worth doing before merging.
src/storage/reclaim.rs:326: The legacy disposition fallback does not ignore the read-only attribute. (more on the line) Do: Implement a handle-based fallback that handles read-only files safely, and test the fallback with a read-only file on a filesystem that rejects the extended flags.Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)
src/storage/reclaim.rs:225: The reported benchmark does not show the gain for the full cleanup players run, including its rescan. (more on the line) Do: Measure several complete cleanups of the same large extraction on the base and head, on the same Windows machine and settings, and report both total and removal times.@fixcan do L1 and L2.Questions (1) (not confirmed from the code; they don't hold the recommendation)
Checks: Still running: 5 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven for the claimed real cleanup: the PR reports 8.3 seconds on the base and 1.7 and 1.9 seconds on the head for 20,000 synthetic files in a Windows debug build. The base has one run, and neither a real extraction nor the complete cleanup workflow was measured.
Other systems: The directory-check change affects Windows and Linux. Windows also changes identity opens used by storage measurement and uses new deletion APIs; FAT/exFAT and network drives were not tested. The Linux removal branch was not compiled or run by the author. This does not affect rendering, audio, input, or saves directly.
Switches: None.
Reviewed:
524a1222c0againstc1bc2e0059: Read AGENTS.md, CONTRIBUTING.md, docs/pull-requests.md, the commits, all changed code and tests, and the relevant scan, identity, link-check and removal paths. Skimmed the remaining storage and scan code. No review checklist or pull request template was present.; nothing run (a code review).Checked and fine:
Testing: No code or tests were run, as requested. The author reports Windows formatting and Clippy passing, with 270 tests passing and 12 failures also present on the base; CI is still running.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by Jiro113. Nothing was run; a maintainer decides.
@ -238,0 +222,4 @@files: &BTreeMap<PathBuf, File>,mut progress: impl FnMut(usize, usize),) -> Result<()> {let total = files.len();L3 (should fix): The reported benchmark does not show the gain for the full cleanup players run, including its rescan.
When: A real extraction can spend a different share of its time rescanning and checking files than the synthetic removal-only benchmark, so its overall speedup may differ substantially.
Do: Measure several complete cleanups of the same large extraction on the base and head, on the same Windows machine and settings, and report both total and removal times.
@ -238,0 +252,4 @@.iter().all(|part| fs::symlink_metadata(part).is_ok_and(|m| !super::is_link(&m))){return false;L1 (blocking): A checked directory remains trusted after it is replaced by a link, so file identity no longer confines deletion to the reviewed path.
When: After cleanup removes the first file in a folder, another program moves that folder elsewhere and puts a junction or symlink at its old path. The cached check accepts the link, and the remaining files still have the reviewed identities, so cleanup deletes them in the moved folder.
Do: Keep directory handles that prevent or detect replacement while removing their children, or revalidate the path before each removal. Add a test that swaps the folder after the first progress callback.
@ -238,0 +323,4 @@size_of_val(&legacy),) {return Err(std::io::Error::last_os_error()).with_context(|| format!("Could not remove {}.", home::display(path)));L2 (should fix): The legacy disposition fallback does not ignore the read-only attribute.
When: On a filesystem or Windows version that rejects the extended flags, a reviewed read-only file also rejects FileDispositionInfo, so cleanup stops partway through instead of removing it.
Do: Implement a handle-based fallback that handles read-only files safely, and test the fallback with a read-only file on a filesystem that rejects the extended flags.
fix(storage): remove obsolete build files about five times fasterto fix(storage): remove obsolete build files about three times fasterPushed
0e82392for BeanBot's review.L1 (fixed): right, a folder stayed trusted once checked. The per-folder cache is gone. On Windows the handle that deletes a file now gives the path it was reached at (
GetFinalPathNameByHandleW, the callfs::canonicalizemakes during the scan), and it must be the reviewed path, so a link at any level stops the cleanup, with no gap between that check and the removal. Linux checks every folder above each file again, as on main. New testremoval_stops_when_a_folder_becomes_a_link_during_the_cleanupswaps the folder for a junction (symlink on Linux) after the first progress callback: the second file is kept. It fails without the final-path comparison.L2 (not changed): the fallback only runs on file systems without POSIX deletion (FAT/exFAT) or Windows before 10 1809. There,
fs::remove_file, which main used, can't remove a read-only file either:DeleteFileWfails and itsposix_deleteretry uses the same extended flags (stdsys/fs/windows.rs,unlink). So this isn't a regression, and a fallback that clears the attribute couldn't be tested here (mounting a FAT volume needs an administrator). Noted under Still to test.L3 (measured): three complete cleanups (review, then Clean up: scan again and removal) of the same synthetic 50,000-file extraction on main and on this PR, same Windows machine: Clean up 23.9β35.7 s on main, 8.4β9.9 s here; removal alone about 21β30 s against 6.3β7.6 s. The description and title now say about three times, not five. A real extraction wasn't measured.
@review
Recommendation: Approve. The directory check is repeated for each removal, and the reported Windows measurements show a substantial full-cleanup gain. The legacy read-only fallback remains a minor limitation on file systems or Windows versions without extended disposition support. Recommend approval; not approved on the forge.
Cleanup of obsolete build files uses fewer Windows file opens and checks the reviewed file and its resolved path through the deletion handle. This adds platform-specific code but reduces the measured cleanup time while retaining the reviewed-path check.
Should fix (1): not blocking, but worth doing before merging.
src/storage/reclaim.rs:326: The legacy disposition fallback does not ignore the read-only attribute. When: On a filesystem or Windows version that rejects the extended flags, a reviewed read-only file also rejects FileDispositionInfo, so cleanup stops partway through instead of removing it. Do: Implement a handle-based fallback that handles read-only files safely, and test the fallback with a read-only file on a filesystem that rejects the extended flags.@fixcan do L2.Since the last review (on
524a1222c0)Resolved: L1 (A checked directory remains trusted after it is replaced by a link, so file identity no loβ¦); L3 (The reported benchmark does not show the gain for the full cleanup players run, includingβ¦)
Still open: L2 (The legacy disposition fallback does not ignore the read-only attribute.)
Checks: Still running: 5 checks.
Also noticed (1; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes. On one Windows 11 machine with a synthetic 50,000-file extraction, three full cleanup runs fell from 23.86β35.66 seconds on main to 8.44β9.92 seconds on this PR. A real extraction was not measured.
Other systems: Linux retains a per-file parent check and path-based removal; its changed branch was not compiled in the reported local run. FAT/exFAT and network drives were not tested. The Windows fallback still cannot remove read-only files where extended disposition is unavailable.
Switches: None.
Reviewed:
0e82392d58againstc1bc2e0059: Read AGENTS.md, CONTRIBUTING.md, the full PR diff, the changes since the ledger, reclaim.rs and reclaim/tests.rs. The storage.rs output was truncated and only portions were reviewed. No review checklist or pull request template was found.; nothing run (a code review).Checked and fine:
Testing: No commands or tests were run. The author reports Windows tests and mutation checks; CI checks were still running.
Overlaps and merge order: Not checked; network access is unavailable.
Automated code review by BeanBot (gpt-6.1-terra), asked for by Jiro113. Nothing was run; a maintainer decides.
@fix
Recommendation: Approve. The Windows cleanup is substantially faster in the reported repeated runs, and the fix preserves the fast path while handling read-only files in the legacy fallback. The fallbackβs filesystem-specific behavior still needs a run on a suitable volume. Recommend approval; not approved on the forge.
What
@fixchangedI changed this pull request: the new head is
43bd13ba8d. I edited its description to match the change.Changed
Nothing was built or run: the checks run again on the new head.
The launcher removes reviewed obsolete build files faster on Windows while retaining identity and path checks. The legacy fallback adds code to clear the read-only attribute and restore it if deletion fails.
Checks: they run again on this head; a failure shows on the pull request.
Also noticed (5; not asked for, not blocking)
More: does it help, other systems, switches, what was read
Does it help: Yes. The author reports three synthetic Windows cleanups of 50,000 files: 23.86β35.66 seconds on the base and 8.44β9.92 seconds on the PR before the fallback fix. A real extraction was not measured.
Other systems: Linux retains per-file parent checks; its branch was not compiled in the reported local run. FAT/exFAT and network drives have not been tested; the new legacy fallback is Windows-specific.
Switches: LONGSHOT_LEGACY_DELETE_TEST_DIR is added for an ignored Windows test and has no default; it selects a filesystem for that test and does not affect launcher behavior.
Reviewed:
43bd13ba8dagainstc1bc2e0059: Read the repository rules, the PR diff, the fallback and its tests, and the surrounding cleanup and identity code. Skimmed the larger storage and scan modules and the reported runs; no PR template or review checklist was present.; nothing run (a code review).Checked and fine:
Testing: No commands from the project were run. The author reports Windows formatting and Clippy passing, 271 tests passing with 12 failures also present on main, and the Tooling release suite passing; CI has not run on this head.
Overlaps and merge order: Not available from the supplied information.
Automated code review by BeanBot (gpt-6.1-terra), asked for by BeanBot, after its fix. Nothing was run; a maintainer decides.
Jiro113 referenced this pull request2026-12-02 20:10:39 +00:00