Skip to content

Commit ca42f1f

Browse files
tmwhbradfitz
authored andcommitted
cmd/go: clear cmd cache to avoid duplicate loads errors
go get -u all command updates all packages including standard commands. We need to get commands evicted from their cache to avoid loading old versions of the packages evicted from the packages cache. Fixes #14444 Change-Id: Icd581a26e1db34ca634aba595fed62b097094c2f Reviewed-on: https://go-review.googlesource.com/19899 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent b24c6fb commit ca42f1f

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/cmd/go/get.go

+8
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ func runGet(cmd *Command, args []string) {
119119
delete(packageCache, name)
120120
}
121121

122+
// In order to rebuild packages information completely,
123+
// we need to clear commands cache. Command packages are
124+
// referring to evicted packages from the package cache.
125+
// This leads to duplicated loads of the standard packages.
126+
for name := range cmdCache {
127+
delete(cmdCache, name)
128+
}
129+
122130
args = importPaths(args)
123131
packagesForBuild(args)
124132

src/cmd/go/go_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -2789,3 +2789,15 @@ func TestCgoConsistentResults(t *testing.T) {
27892789
t.Error("building cgotest twice did not produce the same output")
27902790
}
27912791
}
2792+
2793+
// Issue 14444: go get -u .../ duplicate loads errors
2794+
func TestGoGetUpdateAllDoesNotTryToLoadDuplicates(t *testing.T) {
2795+
testenv.MustHaveExternalNetwork(t)
2796+
2797+
tg := testgo(t)
2798+
defer tg.cleanup()
2799+
tg.makeTempdir()
2800+
tg.setenv("GOPATH", tg.path("."))
2801+
tg.run("get", "-u", ".../")
2802+
tg.grepStderrNot("duplicate loads of", "did not remove old packages from cache")
2803+
}

0 commit comments

Comments
 (0)