Prune superseded asset-cache extractions after an upgrade - #207
Merged
Conversation
Each new version extracts its embedded scripts to ~/Library/Caches/wp-ops/assets-<version> and nothing ever removed the directory the previous version left behind, so the cache grew by one tree per upgrade indefinitely — 29 of them, back to 3.23.2, on a machine that had been upgrading since the Go CLI shipped. Sweep the cache parent right after an extraction succeeds, keeping the current version, the two most recent superseded extractions, and anything under 24 hours old. Both guards exist for the same reason the staged-playbook sweep in internal/exec has an age threshold: an older binary may still be running, reading its own scripts for the length of a database or files pull, and the version it is reading is most likely the one just replaced. The sweep hangs off the extraction path rather than every run, so the fast path — this version is already extracted — still does no directory scanning, and a machine that never upgrades never sweeps because nothing there is stale. Stale .extract-* temp directories are swept on the same age rule; the extraction defer already removes them, so survivors belong to a run that was killed mid-extraction.
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.
Summary
A binary installed via Homebrew has no checkout to run from, so it extracts its
embedded scripts to a version-stamped cache directory
(
~/Library/Caches/wp-ops/assets-<version>) on first run. Nothing ever removedthe directory the previous version left behind, so the cache grew by one full
tree per upgrade indefinitely — 29 of them, back to 3.23.2, on a machine that
had been upgrading since the Go CLI shipped.
Changes
extractedAssetsRoot()now sweeps the cache parent immediately after asuccessful extraction, keeping:
keptPreviousExtractions)staleExtractionAge)Leftover
.extract-*temp directories are swept on the same age rule — theextraction path's own
deferremoves them, so any survivor belongs to a runthat was killed mid-extraction and owns nothing.
Both guards exist for the same reason
sweepStalePlaybookStagingingo/internal/exec/ansible.gohas an age threshold: an older binary may stillbe running and reading its own scripts for the length of a database or files
pull, and the version it is reading is most likely the one that was just
replaced. The sweep is best-effort throughout — a cache entry that can't be
read or removed is left alone rather than failing the command the user actually
ran.
Hanging the sweep off the extraction path rather than off every run keeps the
fast path (this version is already extracted) free of any directory scanning.
Testing
go test ./...passes. New coverage ingo/cmd/env_test.go:extractions, young temp dirs, and unrelated cache entries all survive
.extract-*dirs are removed