From ffbcd89f629509eef4524a1c824c4cce507ed6f1 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 13 Mar 2013 23:32:12 -0400 Subject: [PATCH] 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 --- src/cmd/go/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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) { -- 2.48.1