Skip to content

clean: clean cache with -n should only print remove commands. #27470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/cmd/go/internal/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,15 @@ func runClean(cmd *base.Command, args []string) {
if cfg.BuildN || cfg.BuildX {
b.Showcmd("", "rm -r %s", strings.Join(subdirs, " "))
}
printedErrors := false
for _, d := range subdirs {
// Only print the first error - there may be many.
// This also mimics what os.RemoveAll(dir) would do.
if err := os.RemoveAll(d); err != nil && !printedErrors {
printedErrors = true
base.Errorf("go clean -cache: %v", err)
if !cfg.BuildN {
printedErrors := false
for _, d := range subdirs {
// Only print the first error - there may be many.
// This also mimics what os.RemoveAll(dir) would do.
if err := os.RemoveAll(d); err != nil && !printedErrors {
printedErrors = true
base.Errorf("go clean -cache: %v", err)
}
}
}
}
Expand Down
17 changes: 17 additions & 0 deletions src/cmd/go/testdata/script/clean_cache.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Set up fresh GOCACHE.
env GOCACHE=$WORK/gocache
mkdir $GOCACHE

go build lib.go

# Would only print the remove commands
go clean -cache -n
stdout 'gocache/[0-9a-z][0-9a-z]'
exists $WORK/gocache/01

# Would actually run the remove commands
go clean -cache
! exists $WORK/gocache/01

-- lib.go --
package lib