Skip to content

Commit 948dc1c

Browse files
committed
clean: clean cache with -n should only print remove commands.
runClean when cleanCache should not execute remove commands when cfg.BuildN = true, but only print them. Fixes #27469.
1 parent 5188c87 commit 948dc1c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/cmd/go/internal/clean/clean.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,15 @@ func runClean(cmd *base.Command, args []string) {
126126
if cfg.BuildN || cfg.BuildX {
127127
b.Showcmd("", "rm -r %s", strings.Join(subdirs, " "))
128128
}
129-
printedErrors := false
130-
for _, d := range subdirs {
131-
// Only print the first error - there may be many.
132-
// This also mimics what os.RemoveAll(dir) would do.
133-
if err := os.RemoveAll(d); err != nil && !printedErrors {
134-
printedErrors = true
135-
base.Errorf("go clean -cache: %v", err)
129+
if !cfg.BuildN {
130+
printedErrors := false
131+
for _, d := range subdirs {
132+
// Only print the first error - there may be many.
133+
// This also mimics what os.RemoveAll(dir) would do.
134+
if err := os.RemoveAll(d); err != nil && !printedErrors {
135+
printedErrors = true
136+
base.Errorf("go clean -cache: %v", err)
137+
}
136138
}
137139
}
138140
}

0 commit comments

Comments
 (0)