From: Russ Cox Date: Thu, 14 Mar 2013 03:32:12 +0000 (-0400) Subject: cmd/go: allow ~ in middle of path, just not at beginning X-Git-Tag: go1.1rc2~519 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ffbcd89f629509eef4524a1c824c4cce507ed6f1;p=gostls13.git cmd/go: allow ~ in middle of path, just not at beginning An earlier CL disallowed ~ anywhere in GOPATH, to avoid problems with GOPATH='~/home' instead of GOPATH=~/home. But ~ is only special in the shell at the beginning of each of the paths in the list, and some paths do have ~ in the middle. So relax the requirement slightly. Fixes #4140. R=golang-dev, dsymonds CC=golang-dev https://golang.org/cl/7799045 --- diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 8334e0eb78..61e6299681 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -130,8 +130,11 @@ func main() { fmt.Fprintf(os.Stderr, "warning: GOPATH set to GOROOT (%s) has no effect\n", gopath) } else { for _, p := range filepath.SplitList(gopath) { - if strings.Contains(p, "~") && runtime.GOOS != "windows" { - fmt.Fprintf(os.Stderr, "go: GOPATH entry cannot contain shell metacharacter '~': %q\n", p) + // Note: using HasPrefix instead of Contains because a ~ can appear + // in the middle of directory elements, such as /tmp/git-1.8.2~rc3 + // or C:\PROGRA~1. Only ~ as a path prefix has meaning to the shell. + if strings.HasPrefix(p, "~") { + fmt.Fprintf(os.Stderr, "go: GOPATH entry cannot start with shell metacharacter '~': %q\n", p) os.Exit(2) } if build.IsLocalImport(p) {