From 682b24125499c3779613897eca06e51b62e26fbd Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Thu, 21 Jul 2016 16:51:57 +1000 Subject: [PATCH] imports: make filepath.Rel work on windows filepath.Rel will always fail if one parameter starts with drive letter and the other does not. Make both filepath.Rel parameters absolute paths, to give it chance to succeed. Fixes broken tools build on windows. Change-Id: Ibefcfe283f28977503323f01bc3a698478227f84 Reviewed-on: https://go-review.googlesource.com/25120 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- imports/fix.go | 8 ++++++-- imports/fix_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/imports/fix.go b/imports/fix.go index f2fec885..880c1690 100644 --- a/imports/fix.go +++ b/imports/fix.go @@ -827,11 +827,15 @@ func canUse(filename, dir string) bool { // or bar/vendor or bar/internal. // After stripping all the leading ../, the only okay place to see vendor or internal // is at the very beginning of the path. - abs, err := filepath.Abs(filename) + absfile, err := filepath.Abs(filename) if err != nil { return false } - rel, err := filepath.Rel(abs, dir) + absdir, err := filepath.Abs(dir) + if err != nil { + return false + } + rel, err := filepath.Rel(absfile, absdir) if err != nil { return false } diff --git a/imports/fix_test.go b/imports/fix_test.go index 7c7018e9..e1179e9c 100644 --- a/imports/fix_test.go +++ b/imports/fix_test.go @@ -829,7 +829,7 @@ func TestFixImports(t *testing.T) { func TestImportSymlinks(t *testing.T) { switch runtime.GOOS { case "windows", "plan9": - t.Skip("skipping test on %q as there are no symlinks", runtime.GOOS) + t.Skipf("skipping test on %q as there are no symlinks", runtime.GOOS) } newGoPath, err := ioutil.TempDir("", "symlinktest")