]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore volume name case when checking vendor path
authorDaniel Theophanes <kardianos@gmail.com>
Mon, 22 Jun 2015 17:59:24 +0000 (10:59 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 7 Jul 2015 21:02:17 +0000 (21:02 +0000)
Fixes #11409

Change-Id: Ic1610e124b2d8b2b12310fc9538d5078cc7302a0
Reviewed-on: https://go-review.googlesource.com/11316
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/main.go
src/cmd/go/pkg.go
src/cmd/go/vendor_test.go

index 1bd75401cb01ea46cacadcbbbefe4666ba451c12..659484b76afa98f93af470ef658ae70be8dd1d31 100644 (file)
@@ -474,6 +474,28 @@ func hasPathPrefix(s, prefix string) bool {
        }
 }
 
+// hasFilePathPrefix reports whether the filesystem path s begins with the
+// elements in prefix.
+func hasFilePathPrefix(s, prefix string) bool {
+       sv := strings.ToUpper(filepath.VolumeName(s))
+       pv := strings.ToUpper(filepath.VolumeName(prefix))
+       s = s[len(sv):]
+       prefix = prefix[len(pv):]
+       switch {
+       default:
+               return false
+       case sv != pv:
+               return false
+       case len(s) == len(prefix):
+               return s == prefix
+       case len(s) > len(prefix):
+               if prefix != "" && prefix[len(prefix)-1] == filepath.Separator {
+                       return strings.HasPrefix(s, prefix)
+               }
+               return s[len(prefix)] == filepath.Separator && s[:len(prefix)] == prefix
+       }
+}
+
 // treeCanMatchPattern(pattern)(name) reports whether
 // name or children of name can possibly match pattern.
 // Pattern is the same limited glob accepted by matchPattern.
index 0990c4563be8a686da23a410bbfd933956432024..51567b5afbef9b55638cd9a142586f339bb4c6ad 100644 (file)
@@ -360,7 +360,7 @@ func vendoredImportPath(parent *Package, path string) (found string, searched []
        }
        dir := filepath.Clean(parent.Dir)
        root := filepath.Clean(parent.Root)
-       if !strings.HasPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator {
+       if !hasFilePathPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator {
                fatalf("invalid vendoredImportPath: dir=%q root=%q separator=%q", dir, root, string(filepath.Separator))
        }
        vpath := "vendor/" + path
index 3b99a29d98cd4ebb1b76dbee7a9d2fc85c500460..389fd5efb00ca79707f40b3d26de085983d65e81 100644 (file)
@@ -54,6 +54,22 @@ func TestVendorRun(t *testing.T) {
        tg.grepStdout("hello, world", "missing hello world output")
 }
 
+func TestVendorGOPATH(t *testing.T) {
+       tg := testgo(t)
+       defer tg.cleanup()
+       changeVolume := func(s string, f func(s string) string) string {
+               vol := filepath.VolumeName(s)
+               return f(vol) + s[len(vol):]
+       }
+       gopath := changeVolume(filepath.Join(tg.pwd(), "testdata"), strings.ToLower)
+       tg.setenv("GOPATH", gopath)
+       tg.setenv("GO15VENDOREXPERIMENT", "1")
+       cd := changeVolume(filepath.Join(tg.pwd(), "testdata/src/vend/hello"), strings.ToUpper)
+       tg.cd(cd)
+       tg.run("run", "hello.go")
+       tg.grepStdout("hello, world", "missing hello world output")
+}
+
 func TestVendorTest(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()