bin/get-github-release.go: Use GOPATH/bin by preference to place binary
This commit is contained in:
parent
cacefb9a82
commit
fffdbb31f5
1 changed files with 24 additions and 8 deletions
|
@ -122,25 +122,41 @@ func writable(path string) bool {
|
||||||
|
|
||||||
// Directory to install releases in by default
|
// Directory to install releases in by default
|
||||||
//
|
//
|
||||||
// Find writable directories on $PATH. Use the first writable
|
// Find writable directories on $PATH. Use $GOPATH/bin if that is on
|
||||||
// directory which is in $HOME or failing that the first writable
|
// the path and writable or use the first writable directory which is
|
||||||
// directory.
|
// in $HOME or failing that the first writable directory.
|
||||||
//
|
//
|
||||||
// Returns "" if none of the above were found
|
// Returns "" if none of the above were found
|
||||||
func defaultBinDir() string {
|
func defaultBinDir() string {
|
||||||
home := os.Getenv("HOME")
|
home := os.Getenv("HOME")
|
||||||
var binDir string
|
var (
|
||||||
|
bin string
|
||||||
|
homeBin string
|
||||||
|
goHomeBin string
|
||||||
|
gopath = os.Getenv("GOPATH")
|
||||||
|
)
|
||||||
for _, dir := range strings.Split(os.Getenv("PATH"), ":") {
|
for _, dir := range strings.Split(os.Getenv("PATH"), ":") {
|
||||||
if writable(dir) {
|
if writable(dir) {
|
||||||
if strings.HasPrefix(dir, home) {
|
if strings.HasPrefix(dir, home) {
|
||||||
return dir
|
if homeBin != "" {
|
||||||
|
homeBin = dir
|
||||||
|
}
|
||||||
|
if gopath != "" && strings.HasPrefix(dir, gopath) && goHomeBin == "" {
|
||||||
|
goHomeBin = dir
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if binDir != "" {
|
if bin == "" {
|
||||||
binDir = dir
|
bin = dir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return binDir
|
if goHomeBin != "" {
|
||||||
|
return goHomeBin
|
||||||
|
}
|
||||||
|
if homeBin != "" {
|
||||||
|
return homeBin
|
||||||
|
}
|
||||||
|
return bin
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the body or an error message
|
// read the body or an error message
|
||||||
|
|
Loading…
Reference in a new issue