diff options
| author | cuiweixie <cuiweixie@gmail.com> | 2022-08-26 15:11:40 +0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-08-30 17:22:49 +0000 |
| commit | c22865fcfa1ec434e5655c652c6376fa2d0eb821 (patch) | |
| tree | 21e98439e2eab491435b7ffa71efc94df86bc6d9 /src | |
| parent | 67d85ad00f9d9be0cc2bb1bb96d01c3d40dcb376 (diff) | |
| download | go-c22865fcfa1ec434e5655c652c6376fa2d0eb821.tar.xz | |
cmd/go: go clean should not accept flags like -modcache with packages
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/go/internal/clean/clean.go | 17 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/clean_cache_n.txt | 3 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/clean_testcache.txt | 2 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/mod_clean_cache.txt | 3 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/test_fuzz_cache.txt | 3 |
5 files changed, 28 insertions, 0 deletions
diff --git a/src/cmd/go/internal/clean/clean.go b/src/cmd/go/internal/clean/clean.go index 37e126ac8b..2417cc077e 100644 --- a/src/cmd/go/internal/clean/clean.go +++ b/src/cmd/go/internal/clean/clean.go @@ -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. diff --git a/src/cmd/go/testdata/script/clean_cache_n.txt b/src/cmd/go/testdata/script/clean_cache_n.txt index 4497b36bc3..72f9abf9ae 100644 --- a/src/cmd/go/testdata/script/clean_cache_n.txt +++ b/src/cmd/go/testdata/script/clean_cache_n.txt @@ -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 diff --git a/src/cmd/go/testdata/script/clean_testcache.txt b/src/cmd/go/testdata/script/clean_testcache.txt index b3f32fe696..3f98602c4e 100644 --- a/src/cmd/go/testdata/script/clean_testcache.txt +++ b/src/cmd/go/testdata/script/clean_testcache.txt @@ -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. diff --git a/src/cmd/go/testdata/script/mod_clean_cache.txt b/src/cmd/go/testdata/script/mod_clean_cache.txt index 01fbc381e0..2b8e820653 100644 --- a/src/cmd/go/testdata/script/mod_clean_cache.txt +++ b/src/cmd/go/testdata/script/mod_clean_cache.txt @@ -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 -- diff --git a/src/cmd/go/testdata/script/test_fuzz_cache.txt b/src/cmd/go/testdata/script/test_fuzz_cache.txt index 19fb764add..752ab3adec 100644 --- a/src/cmd/go/testdata/script/test_fuzz_cache.txt +++ b/src/cmd/go/testdata/script/test_fuzz_cache.txt @@ -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 |
