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

cmd/go: clean -cache -n should not delete cache #39250

Closed
jquirke opened this issue May 26, 2020 · 4 comments
Closed

cmd/go: clean -cache -n should not delete cache #39250

jquirke opened this issue May 26, 2020 · 4 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@jquirke
Copy link
Contributor

jquirke commented May 26, 2020

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

$ go version
go version go1.14.3 darwin/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="/Users/qjeremy/Library/Caches/go-build"
GOENV="/Users/qjeremy/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/qjeremy/gocode"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.14.3/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.14.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/z7/k_sywh750_93syv7f394mq8c0000gn/T/go-build676007682=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. See that there are cache artifacts from prior builds.
qjeremy-C02TX0NYHTDG:wayfare qjeremy$ ls -l `go env GOCACHE` | head -10
total 24
drwxr-xr-x  3 qjeremy  staff   96 May 25 22:11 00
drwxr-xr-x  3 qjeremy  staff   96 May 25 22:11 01
drwxr-xr-x  4 qjeremy  staff  128 May 25 22:11 02
drwxr-xr-x  2 qjeremy  staff   64 May 25 22:11 03
drwxr-xr-x  2 qjeremy  staff   64 May 25 22:11 04
drwxr-xr-x  3 qjeremy  staff   96 May 25 22:11 05
drwxr-xr-x  5 qjeremy  staff  160 May 25 22:11 06
drwxr-xr-x  5 qjeremy  staff  160 May 25 22:11 07
drwxr-xr-x  4 qjeremy  staff  128 May 25 22:11 08
  1. Attempt to clean the cache using go clean -cache but with the -n flag, which according to documentation, states that it only prints the commands it would run, not run them.
$go clean -cache -n Output
rm -r /Users/qjeremy/Library/Caches/go-build/00 /Users/qjeremy/Library/Caches/go-build/01 /Users/qjeremy/Library/Caches/go-build/02 /Users/qjeremy/Library/Caches/go-build/03 /Users/qjeremy/Library/Caches/go-build/04 /Users/qjeremy/Library/Caches/go-build/05 /Users/qjeremy/Library/Caches/go-build/06 /Users/qjeremy/Library/Caches/go-build/07 /Users/qjeremy/Library/Caches/go-build/08 /Users/qjeremy/Library/Caches/go-build/09 /Users/qjeremy/Library/Caches/go-build/0a /Users/qjeremy/Library/Caches/go-build/0b /Users/qjeremy/Library/Caches/go-build/0c /Users/qjeremy/Library/Caches/go-build/0d /Users/qjeremy/Library/Caches/go-build/0e /Users/qjeremy/Library/Caches/go-build/0f /Users/qjeremy/Library/Caches/go-build/10 /Users/qjeremy/Library/Caches/go-build/11 /Users/qjeremy/Library/Caches/go-build/12 /Users/qjeremy/Library/Caches/go-build/13 /Users/qjeremy/Library/Caches/go-build/14 /Users/qjeremy/Library/Caches/go-build/15 /Users/qjeremy/Library/Caches/go-build/16 /Users/qjeremy/Library/Caches/go-build/17 /Users/qjeremy/Library/Caches/go-build/18 /Users/qjeremy/Library/Caches/go-build/19 /Users/qjeremy/Library/Caches/go-build/1a /Users/qjeremy/Library/Caches/go-build/1b /Users/qjeremy/Library/Caches/go-build/1c /Users/qjeremy/Library/Caches/go-build/1d /Users/qjeremy/Library/Caches/go-build/1e /Users/qjeremy/Library/Caches/go-build/1f /Users/qjeremy/Library/Caches/go-build/20 /Users/qjeremy/Library/Caches/go-build/21 /Users/qjeremy/Library/Caches/go-build/22 /Users/qjeremy/Library/Caches/go-build/23 /Users/qjeremy/Library/Caches/go-build/24 /Users/qjeremy/Library/Caches/go-build/25 /Users/qjeremy/Library/Caches/go-build/26 /Users/qjeremy/Library/Caches/go-build/27 /Users/qjeremy/Library/Caches/go-build/28 /Users/qjeremy/Library/Caches/go-build/29 /Users/qjeremy/Library/Caches/go-build/2a /Users/qjeremy/Library/Caches/go-build/2b /Users/qjeremy/Library/Caches/go-build/2c /Users/qjeremy/Library/Caches/go-build/2d /Users/qjeremy/Library/Caches/go-build/2e /Users/qjeremy/Library/Caches/go-build/2f /Users/qjeremy/Library/Caches/go-build/30 /Users/qjeremy/Library/Caches/go-build/31 /Users/qjeremy/Library/Caches/go-build/32 /Users/qjeremy/Library/Caches/go-build/33 /Users/qjeremy/Library/Caches/go-build/34 /Users/qjeremy/Library/Caches/go-build/35 /Users/qjeremy/Library/Caches/go-build/36 /Users/qjeremy/Library/Caches/go-build/37 /Users/qjeremy/Library/Caches/go-build/38 /Users/qjeremy/Library/Caches/go-build/39 /Users/qjeremy/Library/Caches/go-build/3a /Users/qjeremy/Library/Caches/go-build/3b /Users/qjeremy/Library/Caches/go-build/3c /Users/qjeremy/Library/Caches/go-build/3d /Users/qjeremy/Library/Caches/go-build/3e /Users/qjeremy/Library/Caches/go-build/3f /Users/qjeremy/Library/Caches/go-build/40 /Users/qjeremy/Library/Caches/go-build/41 /Users/qjeremy/Library/Caches/go-build/42 /Users/qjeremy/Library/Caches/go-build/43 /Users/qjeremy/Library/Caches/go-build/44 /Users/qjeremy/Library/Caches/go-build/45 /Users/qjeremy/Library/Caches/go-build/46 /Users/qjeremy/Library/Caches/go-build/47 /Users/qjeremy/Library/Caches/go-build/48 /Users/qjeremy/Library/Caches/go-build/49 /Users/qjeremy/Library/Caches/go-build/4a /Users/qjeremy/Library/Caches/go-build/4b /Users/qjeremy/Library/Caches/go-build/4c /Users/qjeremy/Library/Caches/go-build/4d /Users/qjeremy/Library/Caches/go-build/4e /Users/qjeremy/Library/Caches/go-build/4f /Users/qjeremy/Library/Caches/go-build/50 /Users/qjeremy/Library/Caches/go-build/51 /Users/qjeremy/Library/Caches/go-build/52 /Users/qjeremy/Library/Caches/go-build/53 /Users/qjeremy/Library/Caches/go-build/54 /Users/qjeremy/Library/Caches/go-build/55 /Users/qjeremy/Library/Caches/go-build/56 /Users/qjeremy/Library/Caches/go-build/57 /Users/qjeremy/Library/Caches/go-build/58 /Users/qjeremy/Library/Caches/go-build/59 /Users/qjeremy/Library/Caches/go-build/5a /Users/qjeremy/Library/Caches/go-build/5b /Users/qjeremy/Library/Caches/go-build/5c /Users/qjeremy/Library/Caches/go-build/5d /Users/qjeremy/Library/Caches/go-build/5e /Users/qjeremy/Library/Caches/go-build/5f /Users/qjeremy/Library/Caches/go-build/60 /Users/qjeremy/Library/Caches/go-build/61 /Users/qjeremy/Library/Caches/go-build/62 /Users/qjeremy/Library/Caches/go-build/63 /Users/qjeremy/Library/Caches/go-build/64 /Users/qjeremy/Library/Caches/go-build/65 /Users/qjeremy/Library/Caches/go-build/66 /Users/qjeremy/Library/Caches/go-build/67 /Users/qjeremy/Library/Caches/go-build/68 /Users/qjeremy/Library/Caches/go-build/69 /Users/qjeremy/Library/Caches/go-build/6a /Users/qjeremy/Library/Caches/go-build/6b /Users/qjeremy/Library/Caches/go-build/6c /Users/qjeremy/Library/Caches/go-build/6d /Users/qjeremy/Library/Caches/go-build/6e /Users/qjeremy/Library/Caches/go-build/6f /Users/qjeremy/Library/Caches/go-build/70 /Users/qjeremy/Library/Caches/go-build/71 /Users/qjeremy/Library/Caches/go-build/72 /Users/qjeremy/Library/Caches/go-build/73 /Users/qjeremy/Library/Caches/go-build/74 /Users/qjeremy/Library/Caches/go-build/75 /Users/qjeremy/Library/Caches/go-build/76 /Users/qjeremy/Library/Caches/go-build/77 /Users/qjeremy/Library/Caches/go-build/78 /Users/qjeremy/Library/Caches/go-build/79 /Users/qjeremy/Library/Caches/go-build/7a /Users/qjeremy/Library/Caches/go-build/7b /Users/qjeremy/Library/Caches/go-build/7c /Users/qjeremy/Library/Caches/go-build/7d /Users/qjeremy/Library/Caches/go-build/7e /Users/qjeremy/Library/Caches/go-build/7f /Users/qjeremy/Library/Caches/go-build/80 /Users/qjeremy/Library/Caches/go-build/81 /Users/qjeremy/Library/Caches/go-build/82 /Users/qjeremy/Library/Caches/go-build/83 /Users/qjeremy/Library/Caches/go-build/84 /Users/qjeremy/Library/Caches/go-build/85 /Users/qjeremy/Library/Caches/go-build/86 /Users/qjeremy/Library/Caches/go-build/87 /Users/qjeremy/Library/Caches/go-build/88 /Users/qjeremy/Library/Caches/go-build/89 /Users/qjeremy/Library/Caches/go-build/8a /Users/qjeremy/Library/Caches/go-build/8b /Users/qjeremy/Library/Caches/go-build/8c /Users/qjeremy/Library/Caches/go-build/8d /Users/qjeremy/Library/Caches/go-build/8e /Users/qjeremy/Library/Caches/go-build/8f /Users/qjeremy/Library/Caches/go-build/90 /Users/qjeremy/Library/Caches/go-build/91 /Users/qjeremy/Library/Caches/go-build/92 /Users/qjeremy/Library/Caches/go-build/93 /Users/qjeremy/Library/Caches/go-build/94 /Users/qjeremy/Library/Caches/go-build/95 /Users/qjeremy/Library/Caches/go-build/96 /Users/qjeremy/Library/Caches/go-build/97 /Users/qjeremy/Library/Caches/go-build/98 /Users/qjeremy/Library/Caches/go-build/99 /Users/qjeremy/Library/Caches/go-build/9a /Users/qjeremy/Library/Caches/go-build/9b /Users/qjeremy/Library/Caches/go-build/9c /Users/qjeremy/Library/Caches/go-build/9d /Users/qjeremy/Library/Caches/go-build/9e /Users/qjeremy/Library/Caches/go-build/9f /Users/qjeremy/Library/Caches/go-build/a0 /Users/qjeremy/Library/Caches/go-build/a1 /Users/qjeremy/Library/Caches/go-build/a2 /Users/qjeremy/Library/Caches/go-build/a3 /Users/qjeremy/Library/Caches/go-build/a4 /Users/qjeremy/Library/Caches/go-build/a5 /Users/qjeremy/Library/Caches/go-build/a6 /Users/qjeremy/Library/Caches/go-build/a7 /Users/qjeremy/Library/Caches/go-build/a8 /Users/qjeremy/Library/Caches/go-build/a9 /Users/qjeremy/Library/Caches/go-build/aa /Users/qjeremy/Library/Caches/go-build/ab /Users/qjeremy/Library/Caches/go-build/ac /Users/qjeremy/Library/Caches/go-build/ad /Users/qjeremy/Library/Caches/go-build/ae /Users/qjeremy/Library/Caches/go-build/af /Users/qjeremy/Library/Caches/go-build/b0 /Users/qjeremy/Library/Caches/go-build/b1 /Users/qjeremy/Library/Caches/go-build/b2 /Users/qjeremy/Library/Caches/go-build/b3 /Users/qjeremy/Library/Caches/go-build/b4 /Users/qjeremy/Library/Caches/go-build/b5 /Users/qjeremy/Library/Caches/go-build/b6 /Users/qjeremy/Library/Caches/go-build/b7 /Users/qjeremy/Library/Caches/go-build/b8 /Users/qjeremy/Library/Caches/go-build/b9 /Users/qjeremy/Library/Caches/go-build/ba /Users/qjeremy/Library/Caches/go-build/bb /Users/qjeremy/Library/Caches/go-build/bc /Users/qjeremy/Library/Caches/go-build/bd /Users/qjeremy/Library/Caches/go-build/be /Users/qjeremy/Library/Caches/go-build/bf /Users/qjeremy/Library/Caches/go-build/c0 /Users/qjeremy/Library/Caches/go-build/c1 /Users/qjeremy/Library/Caches/go-build/c2 /Users/qjeremy/Library/Caches/go-build/c3 /Users/qjeremy/Library/Caches/go-build/c4 /Users/qjeremy/Library/Caches/go-build/c5 /Users/qjeremy/Library/Caches/go-build/c6 /Users/qjeremy/Library/Caches/go-build/c7 /Users/qjeremy/Library/Caches/go-build/c8 /Users/qjeremy/Library/Caches/go-build/c9 /Users/qjeremy/Library/Caches/go-build/ca /Users/qjeremy/Library/Caches/go-build/cb /Users/qjeremy/Library/Caches/go-build/cc /Users/qjeremy/Library/Caches/go-build/cd /Users/qjeremy/Library/Caches/go-build/ce /Users/qjeremy/Library/Caches/go-build/cf /Users/qjeremy/Library/Caches/go-build/d0 /Users/qjeremy/Library/Caches/go-build/d1 /Users/qjeremy/Library/Caches/go-build/d2 /Users/qjeremy/Library/Caches/go-build/d3 /Users/qjeremy/Library/Caches/go-build/d4 /Users/qjeremy/Library/Caches/go-build/d5 /Users/qjeremy/Library/Caches/go-build/d6 /Users/qjeremy/Library/Caches/go-build/d7 /Users/qjeremy/Library/Caches/go-build/d8 /Users/qjeremy/Library/Caches/go-build/d9 /Users/qjeremy/Library/Caches/go-build/da /Users/qjeremy/Library/Caches/go-build/db /Users/qjeremy/Library/Caches/go-build/dc /Users/qjeremy/Library/Caches/go-build/dd /Users/qjeremy/Library/Caches/go-build/de /Users/qjeremy/Library/Caches/go-build/df /Users/qjeremy/Library/Caches/go-build/e0 /Users/qjeremy/Library/Caches/go-build/e1 /Users/qjeremy/Library/Caches/go-build/e2 /Users/qjeremy/Library/Caches/go-build/e3 /Users/qjeremy/Library/Caches/go-build/e4 /Users/qjeremy/Library/Caches/go-build/e5 /Users/qjeremy/Library/Caches/go-build/e6 /Users/qjeremy/Library/Caches/go-build/e7 /Users/qjeremy/Library/Caches/go-build/e8 /Users/qjeremy/Library/Caches/go-build/e9 /Users/qjeremy/Library/Caches/go-build/ea /Users/qjeremy/Library/Caches/go-build/eb /Users/qjeremy/Library/Caches/go-build/ec /Users/qjeremy/Library/Caches/go-build/ed /Users/qjeremy/Library/Caches/go-build/ee /Users/qjeremy/Library/Caches/go-build/ef /Users/qjeremy/Library/Caches/go-build/f0 /Users/qjeremy/Library/Caches/go-build/f1 /Users/qjeremy/Library/Caches/go-build/f2 /Users/qjeremy/Library/Caches/go-build/f3 /Users/qjeremy/Library/Caches/go-build/f4 /Users/qjeremy/Library/Caches/go-build/f5 /Users/qjeremy/Library/Caches/go-build/f6 /Users/qjeremy/Library/Caches/go-build/f7 /Users/qjeremy/Library/Caches/go-build/f8 /Users/qjeremy/Library/Caches/go-build/f9 /Users/qjeremy/Library/Caches/go-build/fa /Users/qjeremy/Library/Caches/go-build/fb /Users/qjeremy/Library/Caches/go-build/fc /Users/qjeremy/Library/Caches/go-build/fd /Users/qjeremy/Library/Caches/go-build/fe /Users/qjeremy/Library/Caches/go-build/ff
  1. Verify the cache is NOT removed

What did you expect to see?

The cache should not be removed, but a series of rm command should be printed.

What did you see instead?

The cache was removed, (but the series of rm commands was printed).

Either the documentation is ambiguous (should it apply to clean -cache as well as packages?) or this is a bug.

$ls -l `go env GOCACHE` | head -10
qjeremy-C02TX0NYHTDG:wayfare qjeremy$ ls -l `go env GOCACHE` | head -10
total 24
-rw-r--r--  1 qjeremy  staff  170 Apr 12  2018 README
-rw-r--r--  1 qjeremy  staff   20 May 25 22:01 testexpire.txt
-rw-r--r--  1 qjeremy  staff   10 May 25 21:29 trim.txt
@mvdan mvdan changed the title go clean -cache -n should not delete cache cmd/go: clean -cache -n should not delete cache May 26, 2020
@mvdan mvdan added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels May 26, 2020
@mvdan
Copy link
Member

mvdan commented May 26, 2020

CC @jayconrod @matloob @bcmills

@tpaschalis
Copy link
Contributor

tpaschalis commented May 26, 2020

I can attest to the fact! I just tried with go1.14.3 and the cache was indeed deleted.

From what I see the -n flag in clean.go is defined as part of the buildN build flag.

The flag is populated correctly, but in the if cleanCache block, we do print the commands, but it looks like we're missing a if cfg.BuildN { continue} or a if !cfg.BuildN block like it exists in the clean function.

If it's okay with you, I'll try to open a CL and get this fixed, as well as see if any tests exist to avoid this in the future.

@mvdan
Copy link
Member

mvdan commented May 26, 2020

@tpaschalis by all means, send a CL. go clean should have test scripts under src/cmd/go/testdata/script.

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/235140 mentions this issue: cmd/go: clean -cache -n should not delete cache

@golang golang locked and limited conversation to collaborators May 27, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants