Skip to content

Commit 9238a8f

Browse files
author
Bryan C. Mills
committed
cmd/go: skip package loading if explicitly cleaning a cache
Fixes #28680 Fixes #29925 Change-Id: I9f7effb3e7743b96b0b8a797d6e1044b39d9b86b Reviewed-on: https://go-review.googlesource.com/c/go/+/167717 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent cb8054a commit 9238a8f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

src/cmd/go/alldocs.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ The go command builds most objects in a temporary directory,
3333
so go clean is mainly concerned with object files left by other
3434
tools or by manual invocations of go build.
3535
36-
Specifically, clean removes the following files from each of the
36+
If a package argument is given or the -i or -r flag is set,
37+
clean removes the following files from each of the
3738
source directories corresponding to the import paths:
3839
3940
_obj/ old object directory, left from Makefiles
@@ -105,7 +106,16 @@ func init() {
105106
}
106107

107108
func runClean(cmd *base.Command, args []string) {
108-
if len(args) > 0 || !modload.Enabled() || modload.HasModRoot() {
109+
// golang.org/issue/29925: only load packages before cleaning if
110+
// either the flags and arguments explicitly imply a package,
111+
// or no other target (such as a cache) was requested to be cleaned.
112+
cleanPkg := len(args) > 0 || cleanI || cleanR
113+
if (!modload.Enabled() || modload.HasModRoot()) &&
114+
!cleanCache && !cleanModcache && !cleanTestcache {
115+
cleanPkg = true
116+
}
117+
118+
if cleanPkg {
109119
for _, pkg := range load.PackagesAndErrors(args) {
110120
clean(pkg)
111121
}

src/cmd/go/testdata/script/mod_clean_cache.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ go clean -r -modcache
3030
! exists ../replaced/test.out # BUG: should still exist
3131

3232
# 'go clean -modcache' should not download anything before cleaning.
33-
# BUG(golang.org/issue/28680): Today, it does.
3433
go mod edit -require rsc.io/[email protected]
35-
! go clean -modcache # BUG: should succeed
36-
stderr 'finding rsc.io' # BUG: should not resolve module
34+
go clean -modcache
35+
! stderr 'finding rsc.io'
3736
go mod edit -droprequire rsc.io/quote
3837

3938
-- go.mod --

0 commit comments

Comments
 (0)