]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: go clean should not accept flags like -modcache with packages
authorcuiweixie <cuiweixie@gmail.com>
Fri, 26 Aug 2022 07:11:40 +0000 (15:11 +0800)
committerGopher Robot <gobot@golang.org>
Tue, 30 Aug 2022 17:22:49 +0000 (17:22 +0000)
For #53725

Change-Id: I99a85b437d5f918dba74c4eccefcf8087193646a
Reviewed-on: https://go-review.googlesource.com/c/go/+/425874
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/cmd/go/internal/clean/clean.go
src/cmd/go/testdata/script/clean_cache_n.txt
src/cmd/go/testdata/script/clean_testcache.txt
src/cmd/go/testdata/script/mod_clean_cache.txt
src/cmd/go/testdata/script/test_fuzz_cache.txt

index 37e126ac8b79522a0d1f947628e07f0c82f19157..2417cc077e8daa3e0f94f561bbafe8442c5dce6d 100644 (file)
@@ -118,6 +118,23 @@ func init() {
 }
 
 func runClean(ctx context.Context, cmd *base.Command, args []string) {
+       if len(args) > 0 {
+               cacheFlag := ""
+               switch {
+               case cleanCache:
+                       cacheFlag = "-cache"
+               case cleanTestcache:
+                       cacheFlag = "-testcache"
+               case cleanFuzzcache:
+                       cacheFlag = "-fuzzcache"
+               case cleanModcache:
+                       cacheFlag = "-modcache"
+               }
+               if cacheFlag != "" {
+                       base.Fatalf("go: clean %s cannot be used with package arguments", cacheFlag)
+               }
+       }
+
        // golang.org/issue/29925: only load packages before cleaning if
        // either the flags and arguments explicitly imply a package,
        // or no other target (such as a cache) was requested to be cleaned.
index 4497b36bc3d83e698174b884deb3aed33431af32..72f9abf9ae1c821e447b4ce169c0f50fbf419cb6 100644 (file)
@@ -15,6 +15,9 @@ exists $GOCACHE/00
 go clean -cache
 ! exists $GOCACHE/00
 
+! go clean -cache .
+stderr 'go: clean -cache cannot be used with package arguments'
+
 -- main.go --
 package main
 
index b3f32fe696af75b6ba36918f8c102dc5465baa05..3f98602c4ea6a6abf67dfdeeb39cc7e9a56fe349 100644 (file)
@@ -8,6 +8,8 @@ go test x_test.go
 go clean -testcache
 go test x_test.go
 ! stdout 'cached'
+! go clean -testcache ../x
+stderr 'go: clean -testcache cannot be used with package arguments'
 
 # golang.org/issue/29100: 'go clean -testcache' should succeed
 # if the cache directory doesn't exist at all.
index 01fbc381e043b2ae6e543eb50d64f7d5e533d752..2b8e820653b810307677dbc1c2060e9f4b3f27a5 100644 (file)
@@ -35,6 +35,9 @@ go clean -modcache
 ! stderr 'finding rsc.io'
 go mod edit -droprequire rsc.io/quote
 
+! go clean -modcache m
+stderr 'go: clean -modcache cannot be used with package arguments'
+
 -- go.mod --
 module m
 -- m.go --
index 19fb764add7a415511d59f0784a2b42e91ecf076..752ab3adecac65e4ac61e11e8c4b051d0d13c861 100644 (file)
@@ -37,6 +37,9 @@ go test -fuzz=FuzzEmpty -fuzztime=2x .
 stdout 'new interesting: 0'
 stdout 'total: 1'
 
+! go clean -fuzzcache example.com/y
+stderr 'go: clean -fuzzcache cannot be used with package arguments'
+
 -- go.mod --
 module example.com/y