Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mvdan opened this issue Jul 6, 2022 · 6 comments
Projects
Milestone

Comments

@mvdan
Copy link
Member

@mvdan mvdan commented Jul 6, 2022

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.

@mvdan mvdan added the GoCommand label Jul 6, 2022
@hyangah
Copy link
Contributor

@hyangah hyangah commented Jul 6, 2022

I agree that it's better to report an error since this is confusing and the cost of the mistake can be large,
even though this behavior is documented.

Related #32976, which is marked as duplicate of #28835 even though the motivation of the proposal and the proposed command line structure is different.

@mvdan
Copy link
Member Author

@mvdan mvdan commented Jul 7, 2022

Thanks @seankhliao; the same search also works on github: https://cs.github.com/?scopeName=All+repos&scope=&q=%2Fgo+clean%28+-%5Ba-z%5D%2B%29*%28+-%28cache%7Cmodcache%7Ctestcache%7Cfuzzcache%29%29%2B%28+-%5Ba-z%5D%2B%29*+%5Ba-z%5C.%5D%2B%2F

I'm willing to bet that the majority of those lines are buggy. The way they are written, they look like the intent is to e.g. remove the cached test results for a few packages.

Related #32976, which is marked as duplicate of #28835 even though the motivation of the proposal and the proposed command line structure is different.

Good call out, I did not notice that proposal - cc @bcmills. I think this change could be a stepping stone towards that proposal; any people who currently use go clean -flag pkg and who want #28835's behavior will then come show their support for the proposal. Any people who just wanted go clean -flag, as per the current behavior, can simply adjust their commands.

@heschi heschi added the NeedsDecision label Jul 7, 2022
@heschi heschi added this to the Backlog milestone Jul 7, 2022
@mvdan
Copy link
Member Author

@mvdan mvdan commented Aug 3, 2022

@bcmills suggests that I should turn this into a proposal, because it's a CLI change that could potentially break some users. See my reasoning above as to why I think the breakage will be minimal, though.

@mvdan mvdan changed the title cmd/go: go clean should not accept flags like -modcache with packages proposal: cmd/go: go clean should not accept flags like -modcache with packages Aug 3, 2022
@mvdan mvdan removed the NeedsDecision label Aug 3, 2022
@mvdan mvdan modified the milestones: Backlog, Proposal Aug 3, 2022
@ianlancetaylor ianlancetaylor added this to Incoming in Proposals Aug 3, 2022
@rsc
Copy link
Contributor

@rsc rsc commented Aug 3, 2022

Reporting an error sounds fine to me.

@rsc
Copy link
Contributor

@rsc rsc commented Aug 3, 2022

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Active in Proposals Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

6 participants