]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: allow ~ in middle of path, just not at beginning
authorRuss Cox <rsc@golang.org>
Thu, 14 Mar 2013 03:32:12 +0000 (23:32 -0400)
committerRuss Cox <rsc@golang.org>
Thu, 14 Mar 2013 03:32:12 +0000 (23:32 -0400)
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

src/cmd/go/main.go

index 8334e0eb7886734c918e64c940741c3ede585828..61e6299681c172a176b9042d795f8d738acc4fb5 100644 (file)
@@ -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) {