Skip to content

fix: prune fails to remove versions with read-only dirs (#226)#227

Merged
kevincobain2000 merged 2 commits into
masterfrom
fix/prune-readonly-dirs
Jun 15, 2026
Merged

fix: prune fails to remove versions with read-only dirs (#226)#227
kevincobain2000 merged 2 commits into
masterfrom
fix/prune-readonly-dirs

Conversation

@juev

@juev juev commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

Problem

Fixes #226. gobrew prune (and gobrew uninstall) reported versions as
uninstalled, but they stayed in ~/.gobrew/versions and a second prune
produced identical output.

Root cause: cleanVersionDir removed a version with os.RemoveAll and
discarded the error (_ = os.RemoveAll(...)). When a version tree contains a
read-only directory (mode 0555, e.g. a Go module-cache style tree), Unix
removal fails with permission denied because deleting an entry needs write
permission on its parent directory. os.RemoveAll aborts and leaves the tree
in place, while Uninstall printed [Success] ... uninstalled regardless.

Fix

  • Add utils.RemoveAll, which walks the tree and makes every directory
    writable before calling os.RemoveAll.
  • cleanVersionDir now returns the error.
  • Uninstall reports a real [Error] and stops instead of falsely claiming
    success.

Test

TestPruneReadOnlyDir injects a 0555 directory into an installed version and
asserts prune removes it. It fails on the old os.RemoveAll path (expected: false, actual: true) and passes with the fix.

Verification

  • go build ./..., go vet ./... — clean
  • go test -race ./... — pass
  • golangci-lint run ./... — no new issues (only the two pre-existing ones on
    master: gocritic/prealloc)

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.

@kevincobain2000 kevincobain2000 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohh
Thanks!

@kevincobain2000 kevincobain2000 merged commit b159aee into master Jun 15, 2026
10 checks passed
@kevincobain2000 kevincobain2000 deleted the fix/prune-readonly-dirs branch June 15, 2026 05:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gobrew prune does not seem to work

2 participants