gopkg.in/tools/godep.v80@v80.0.0-20180126220526-ce0bfadeb516/util.go (about) 1 package main 2 3 import ( 4 "path/filepath" 5 "runtime" 6 "strings" 7 ) 8 9 // driveLetterToUpper converts Windows path's drive letters to uppercase. This 10 // is needed when comparing 2 paths with different drive letter case. 11 func driveLetterToUpper(path string) string { 12 if runtime.GOOS != "windows" || path == "" { 13 return path 14 } 15 16 p := path 17 18 // If path's drive letter is lowercase, change it to uppercase. 19 if len(p) >= 2 && p[1] == ':' && 'a' <= p[0] && p[0] <= 'z' { 20 p = string(p[0]+'A'-'a') + p[1:] 21 } 22 23 return p 24 } 25 26 // clean the path and ensure that a drive letter is upper case (if it exists). 27 func cleanPath(path string) string { 28 return driveLetterToUpper(filepath.Clean(path)) 29 } 30 31 // deal with case insensitive filesystems and other weirdness 32 func pathEqual(a, b string) bool { 33 a = cleanPath(a) 34 b = cleanPath(b) 35 return strings.EqualFold(a, b) 36 }