Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
Consolidate path equality checks into pathEqual
Browse files Browse the repository at this point in the history
Instead of repeating the problem every time, fold this stuff into a
function we can use.
  • Loading branch information
Edward Muller committed Feb 26, 2016
1 parent 3153f57 commit b32db8c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os/exec"
"path/filepath"
"runtime"
"strings"
)

// Runs a command in dir.
Expand Down Expand Up @@ -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)
}
6 changes: 3 additions & 3 deletions vcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime"
)

const version = 55
const version = 56

var cmdVersion = &Command{
Name: "version",
Expand Down

0 comments on commit b32db8c

Please sign in to comment.