Skip to content

Commit 24f7d89

Browse files
author
Jay Conrod
committed
cmd/go: 'go get' should not delete binaries when run from $GOBIN
When 'go install' is run without arguments in a directory containing a main package, it deletes an executable file with the same name as the package (presumably created by 'go build' previously). 'go get' in module mode executes the same code after updating and downloading modules. However, the special case was misfiring because we passed an empty list of patterns to InstallPackages. Fixes #32766 Change-Id: I19aca64ee1fb5a216777dd7d559e8e6a45b3e90c Reviewed-on: https://go-review.googlesource.com/c/go/+/183846 Run-TryBot: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 9bf6278 commit 24f7d89

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

src/cmd/go/internal/modget/get.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ func runGet(cmd *base.Command, args []string) {
472472
// and the load and upgrade operations may only add and upgrade modules
473473
// in the build list.
474474
var matches []*search.Match
475-
var install []string
476475
for {
477476
var seenPkgs map[string]bool
478477
seenQuery := make(map[querySpec]bool)
@@ -664,7 +663,7 @@ func runGet(cmd *base.Command, args []string) {
664663
}
665664
work.BuildInit()
666665
pkgs := load.PackagesForBuild(pkgPatterns)
667-
work.InstallPackages(install, pkgs)
666+
work.InstallPackages(pkgPatterns, pkgs)
668667
}
669668

670669
// runQueries looks up modules at target versions in parallel. Results will be
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-- .info --
2+
{"Version": "v1.0.0"}
3+
-- .mod --
4+
module example.com/tools
5+
-- cmd/hello/hello.go --
6+
package main
7+
8+
import "fmt"
9+
10+
func main() {
11+
fmt.Println("hello")
12+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
env GO111MODULE=on
2+
[short] skip
3+
4+
# Test that when 'go get' is run from $GOBIN, it does not delete binaries
5+
# after it installs them. Verifies golang.org/issue/32766.
6+
7+
go get example.com/tools/cmd/hello
8+
9+
# 'go get' should not delete the command when run from $GOPATH/bin
10+
cd $GOPATH/bin
11+
exists hello$GOEXE
12+
go get example.com/tools/cmd/hello
13+
exists hello$GOEXE
14+
15+
# 'go get' should not delete the command when run from a different $GOBIN
16+
mkdir $WORK/bin
17+
cd $WORK/bin
18+
env GOBIN=$WORK/bin
19+
go get example.com/tools/cmd/hello
20+
exists hello$GOEXE

0 commit comments

Comments
 (0)