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.
The text was updated successfully, but these errors were encountered:
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.
@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.
changed the title
cmd/go: go clean should not accept flags like -modcache with packagesAug 3, 2022