Skip to content

cmd/go: go clean should not accept flags like -modcache with packages #53725

@mvdan

Description

@mvdan

What version of Go are you using (go version)?

$ go version
go version devel go1.19-818ffd4247 Tue Jul 5 15:19:44 2022 +0100 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mvdan/.cache/go-build"
GOENV="/home/mvdan/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mvdan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mvdan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/mvdan/tip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/mvdan/tip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.19-818ffd4247 Tue Jul 5 15:19:44 2022 +0100"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mvdan/src/garble/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1584385538=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version devel go1.19-818ffd4247 Tue Jul 5 15:19:44 2022 +0100 linux/amd64
GOROOT/bin/go tool compile -V: compile version devel go1.19-818ffd4247 Tue Jul 5 15:19:44 2022 +0100
uname -sr: Linux 5.18.9-arch1-1
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.35.
gdb --version: GNU gdb (GDB) 12.1

What did you do?

I wanted to simulate fetching a module from proxy.golang.org, and since it is already in my GOMODCACHE, I wanted to delete it from there. So I naively ran:

go clean -modcache some/module/path

What did you expect to see?

I expected only a few files/directories to be deleted from GOMODCACHE.

What did you see instead?

It deleted my entire GOMODCACHE; presumably, the command is equivalent to:

go clean -modcache
go clean some/module/path

Given that flags like -cache, -modcache, -testcache, and -fuzzcache clear the entire cache directories in question, they should reject package arguments, because otherwise they are very easy to be misused or misunderstood.

It is possible that this might break a few users, but I generally doubt it will be many. I haven't seen any uses of go clean pkg in the wild in years. If anyone wants the current behavior of go clean -modcache pkg, they can always do go clean -modcache; go clean pkg as shown above, which is also more explicit.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions