]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: referee another vendor vs symlink fight
authorRuss Cox <rsc@golang.org>
Fri, 21 Oct 2016 19:01:03 +0000 (15:01 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 24 Oct 2016 15:16:08 +0000 (15:16 +0000)
Avoid crash in the specific case reported in #15201 but also
print more useful error message, avoiding slice panic.

Fixes #15201.
Fixes #16167.
Fixes #16566.

Change-Id: I66499621e9678a05bc9b12b0da77906cd7027bdd
Reviewed-on: https://go-review.googlesource.com/31665
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Quentin Smith <quentin@golang.org>
src/cmd/go/go_test.go
src/cmd/go/pkg.go

index 4a82fdef6c11e05edeba00b86ade6b402753c485..f445aef5bd05320d1c718e47faaefe195ad6ac9c 100644 (file)
@@ -1759,6 +1759,27 @@ func TestSymlinksVendor(t *testing.T) {
        tg.run("install")
 }
 
+// Issue 15201.
+func TestSymlinksVendor15201(t *testing.T) {
+       switch runtime.GOOS {
+       case "plan9", "windows":
+               t.Skipf("skipping symlink test on %s", runtime.GOOS)
+       }
+
+       tg := testgo(t)
+       defer tg.cleanup()
+
+       tg.tempDir("gopath/src/x/y/_vendor/src/x")
+       tg.must(os.Symlink("../../..", tg.path("gopath/src/x/y/_vendor/src/x/y")))
+       tg.tempFile("gopath/src/x/y/w/w.go", "package w\nimport \"x/y/z\"\n")
+       tg.must(os.Symlink("../_vendor/src", tg.path("gopath/src/x/y/w/vendor")))
+       tg.tempFile("gopath/src/x/y/z/z.go", "package z\n")
+
+       tg.setenv("GOPATH", tg.path("gopath/src/x/y/_vendor")+string(filepath.ListSeparator)+tg.path("gopath"))
+       tg.cd(tg.path("gopath/src"))
+       tg.run("list", "./...")
+}
+
 func TestSymlinksInternal(t *testing.T) {
        switch runtime.GOOS {
        case "plan9", "windows":
index 69367eefb130bc80dc69fe9c095e09ae47218c52..a3018bce453de48c2c494a57f633530ab0c5969e 100644 (file)
@@ -415,13 +415,26 @@ func vendoredImportPath(parent *Package, path string) (found string) {
 
        dir := filepath.Clean(parent.Dir)
        root := filepath.Join(parent.Root, "src")
-       if !hasFilePathPrefix(dir, root) {
+       if !hasFilePathPrefix(dir, root) || parent.ImportPath != "command-line-arguments" && filepath.Join(root, parent.ImportPath) != dir {
                // Look for symlinks before reporting error.
                dir = expandPath(dir)
                root = expandPath(root)
        }
-       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))
+
+       if !hasFilePathPrefix(dir, root) || len(dir) <= len(root) || dir[len(root)] != filepath.Separator || parent.ImportPath != "command-line-arguments" && filepath.Join(root, parent.ImportPath) != dir {
+               fatalf("unexpected directory layout:\n"+
+                       "       import path: %s\n"+
+                       "       root: %s\n"+
+                       "       dir: %s\n"+
+                       "       expand root: %s\n"+
+                       "       expand dir: %s\n"+
+                       "       separator: %s",
+                       parent.ImportPath,
+                       filepath.Join(parent.Root, "src"),
+                       filepath.Clean(parent.Dir),
+                       root,
+                       dir,
+                       string(filepath.Separator))
        }
 
        vpath := "vendor/" + path