From b32db8cfcaad4ba20d85667d0978d02e68a6207f Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Thu, 25 Feb 2016 14:22:23 -0800 Subject: [PATCH] Consolidate path equality checks into pathEqual Instead of repeating the problem every time, fold this stuff into a function we can use. --- Changelog.md | 3 ++- list.go | 2 +- util.go | 8 ++++++++ vcs.go | 6 +++--- version.go | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 4212848..87e958a 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,6 @@ -# Unreleased +# v56 (2016/02/26) +* replace path comparisons with case insensitive pathEqual() * add versionString() to debug output * Send log output to Stderr diff --git a/list.go b/list.go index 04ffe37..be73ad9 100644 --- a/list.go +++ b/list.go @@ -189,7 +189,7 @@ func findDirForPath(path string, ip *build.Package) (string, error) { debugln("resolving vendor posibilities:", ip.Dir, ip.Root) cr := cleanPath(ip.Root) - for base := cleanPath(ip.Dir); base != cr; base = cleanPath(filepath.Dir(base)) { + for base := cleanPath(ip.Dir); !pathEqual(base, cr); base = cleanPath(filepath.Dir(base)) { s := filepath.Join(base, "vendor", path) debugln("Adding search dir:", s) search = append(search, s) diff --git a/util.go b/util.go index 0476629..df59786 100644 --- a/util.go +++ b/util.go @@ -5,6 +5,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" ) // Runs a command in dir. @@ -50,3 +51,10 @@ func driveLetterToUpper(path string) string { func cleanPath(path string) string { return driveLetterToUpper(filepath.Clean(path)) } + +// deal with case insensitive filesystems and other weirdness +func pathEqual(a, b string) bool { + a = cleanPath(a) + b = cleanPath(b) + return strings.EqualFold(a, b) +} diff --git a/vcs.go b/vcs.go index 285a026..d38fc63 100644 --- a/vcs.go +++ b/vcs.go @@ -125,7 +125,7 @@ func (vf vcsFiles) Contains(path string) bool { // Slow path for case insensitive filesystems // See #310 for f := range vf { - if strings.EqualFold(f, path) { + if pathEqual(f, path) { return true } // git's root command (maybe other vcs as well) resolve symlinks, so try that too @@ -134,7 +134,7 @@ func (vf vcsFiles) Contains(path string) bool { if err != nil { return false } - if strings.EqualFold(f, p) { + if pathEqual(f, p) { return true } } @@ -162,7 +162,7 @@ func (v *VCS) listFiles(dir string) vcsFiles { panic(err) // this should not happen } - if strings.EqualFold(filepath.Dir(path), dir) { + if pathEqual(filepath.Dir(path), dir) { files[path] = true } } diff --git a/version.go b/version.go index 0d1f8d7..4082aa9 100644 --- a/version.go +++ b/version.go @@ -5,7 +5,7 @@ import ( "runtime" ) -const version = 55 +const version = 56 var cmdVersion = &Command{ Name: "version",