@@ -30,7 +30,7 @@ import (
30
30
// same file. In that situation HasFilepathPrefix("/Foo/Bar", "/foo")
31
31
// will return true. The implementation is *not* OS-specific, so a FAT32
32
32
// filesystem mounted on Linux will be handled correctly.
33
- func HasFilepathPrefix (path , prefix string ) bool {
33
+ func HasFilepathPrefix (path , prefix string ) ( bool , error ) {
34
34
// this function is more convoluted then ideal due to need for special
35
35
// handling of volume name/drive letter on Windows. vnPath and vnPrefix
36
36
// are first compared, and then used to initialize initial values of p and
@@ -42,7 +42,7 @@ func HasFilepathPrefix(path, prefix string) bool {
42
42
vnPath := strings .ToLower (filepath .VolumeName (path ))
43
43
vnPrefix := strings .ToLower (filepath .VolumeName (prefix ))
44
44
if vnPath != vnPrefix {
45
- return false
45
+ return false , nil
46
46
}
47
47
48
48
// Because filepath.Join("c:","dir") returns "c:dir", we have to manually
@@ -54,7 +54,7 @@ func HasFilepathPrefix(path, prefix string) bool {
54
54
var dn string
55
55
56
56
if isDir , err := IsDir (path ); err != nil {
57
- return false
57
+ return false , errors . Wrap ( err , "failed to check filepath prefix" )
58
58
} else if isDir {
59
59
dn = path
60
60
} else {
@@ -69,7 +69,7 @@ func HasFilepathPrefix(path, prefix string) bool {
69
69
prefixes := strings .Split (prefix , string (os .PathSeparator ))[1 :]
70
70
71
71
if len (prefixes ) > len (dirs ) {
72
- return false
72
+ return false , nil
73
73
}
74
74
75
75
// d,p are initialized with "/" on *nix and volume name on Windows
@@ -84,7 +84,7 @@ func HasFilepathPrefix(path, prefix string) bool {
84
84
// problematic filesystem is not the last one.
85
85
caseSensitive , err := isCaseSensitiveFilesystem (filepath .Join (d , dirs [i ]))
86
86
if err != nil {
87
- return false
87
+ return false , errors . Wrap ( err , "failed to check filepath prefix" )
88
88
}
89
89
if caseSensitive {
90
90
d = filepath .Join (d , dirs [i ])
@@ -95,11 +95,11 @@ func HasFilepathPrefix(path, prefix string) bool {
95
95
}
96
96
97
97
if p != d {
98
- return false
98
+ return false , nil
99
99
}
100
100
}
101
101
102
- return true
102
+ return true , nil
103
103
}
104
104
105
105
// EquivalentPaths compares the paths passed to check if they are equivalent.
@@ -126,7 +126,11 @@ func EquivalentPaths(p1, p2 string) (bool, error) {
126
126
p2 , p2Filename = filepath .Split (p2 )
127
127
}
128
128
129
- if ! HasFilepathPrefix (p1 , p2 ) || ! HasFilepathPrefix (p2 , p1 ) {
129
+ if isPrefix1 , err := HasFilepathPrefix (p1 , p2 ); err != nil {
130
+ return false , errors .Wrap (err , "failed to check for path equivalence" )
131
+ } else if isPrefix2 , err := HasFilepathPrefix (p2 , p1 ); err != nil {
132
+ return false , errors .Wrap (err , "failed to check for path equivalence" )
133
+ } else if ! isPrefix1 || ! isPrefix2 {
130
134
return false , nil
131
135
}
132
136
@@ -218,6 +222,11 @@ func isCaseSensitiveFilesystem(dir string) (bool, error) {
218
222
219
223
aInfo , err := os .Stat (alt )
220
224
if err != nil {
225
+ // If the file doesn't exists, assume we are on a case-sensitive filesystem.
226
+ if os .IsNotExist (err ) {
227
+ return true , nil
228
+ }
229
+
221
230
return false , errors .Wrap (err , "could not determine the case-sensitivity of the filesystem" )
222
231
}
223
232
0 commit comments