fix: prune fails to remove versions with read-only dirs (#226)#227
Merged
Conversation
os.RemoveAll returns 'permission denied' and leaves the directory in place when a version tree contains read-only directories (e.g. Go module-cache style trees with mode 0555). cleanVersionDir swallowed the error, so prune/uninstall reported success while every version stayed on disk and a second prune produced identical output. Add utils.RemoveAll, which makes directories writable before removing, return the error from cleanVersionDir, and report a real failure from Uninstall instead of a false success.
The windows build used actions/setup-go without a version, so it ran the runner's preinstalled Go (1.24.13) against go.mod's 'go 1.26.0' directive with GOTOOLCHAIN=local, failing with 'go.mod requires go >= 1.26.0'. Read the version from go.mod so the job tracks the module requirement.
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.
Problem
Fixes #226.
gobrew prune(andgobrew uninstall) reported versions asuninstalled, but they stayed in
~/.gobrew/versionsand a secondpruneproduced identical output.
Root cause:
cleanVersionDirremoved a version withos.RemoveAllanddiscarded the error (
_ = os.RemoveAll(...)). When a version tree contains aread-only directory (mode
0555, e.g. a Go module-cache style tree), Unixremoval fails with
permission deniedbecause deleting an entry needs writepermission on its parent directory.
os.RemoveAllaborts and leaves the treein place, while
Uninstallprinted[Success] ... uninstalledregardless.Fix
utils.RemoveAll, which walks the tree and makes every directorywritable before calling
os.RemoveAll.cleanVersionDirnow returns the error.Uninstallreports a real[Error]and stops instead of falsely claimingsuccess.
Test
TestPruneReadOnlyDirinjects a0555directory into an installed version andasserts prune removes it. It fails on the old
os.RemoveAllpath (expected: false, actual: true) and passes with the fix.Verification
go build ./...,go vet ./...— cleango test -race ./...— passgolangci-lint run ./...— no new issues (only the two pre-existing ones onmaster:gocritic/prealloc)