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 <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
55296b3beb
commit
682b241254
|
@ -827,11 +827,15 @@ func canUse(filename, dir string) bool {
|
||||||
// or bar/vendor or bar/internal.
|
// or bar/vendor or bar/internal.
|
||||||
// After stripping all the leading ../, the only okay place to see vendor or internal
|
// After stripping all the leading ../, the only okay place to see vendor or internal
|
||||||
// is at the very beginning of the path.
|
// is at the very beginning of the path.
|
||||||
abs, err := filepath.Abs(filename)
|
absfile, err := filepath.Abs(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
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 {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -829,7 +829,7 @@ func TestFixImports(t *testing.T) {
|
||||||
func TestImportSymlinks(t *testing.T) {
|
func TestImportSymlinks(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "windows", "plan9":
|
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")
|
newGoPath, err := ioutil.TempDir("", "symlinktest")
|
||||||
|
|
Loading…
Reference in New Issue