Skip to content

Commit 3137bb2

Browse files
committed
Handle Windows 8.3 paths in EquivalentTo method
1 parent 9812a6a commit 3137bb2

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

paths.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -524,15 +524,22 @@ func (p *Path) EquivalentTo(other *Path) bool {
524524
if p.Clean().path == other.Clean().path {
525525
return true
526526
}
527-
absP, err := p.Abs()
528-
if err != nil {
529-
return false
527+
528+
if infoP, err := p.Stat(); err != nil {
529+
// go ahead with the next test...
530+
} else if infoOther, err := other.Stat(); err != nil {
531+
// go ahead with the next test...
532+
} else if os.SameFile(infoP, infoOther) {
533+
return true
530534
}
531-
absOther, err := other.Abs()
532-
if err != nil {
535+
536+
if absP, err := p.Abs(); err != nil {
537+
return false
538+
} else if absOther, err := other.Abs(); err != nil {
533539
return false
540+
} else {
541+
return absP.path == absOther.path
534542
}
535-
return absP.path == absOther.path
536543
}
537544

538545
// Parents returns all the parents directories of the current path. If the path is absolute

paths_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ package paths
3131

3232
import (
3333
"path/filepath"
34+
"runtime"
3435
"strings"
3536
"testing"
3637

@@ -311,6 +312,13 @@ func TestEquivalentPaths(t *testing.T) {
311312
require.True(t, New("file1", "abc").EquivalentTo(New("file1", "abc", "def", "..")))
312313
require.True(t, wd.Join("file1").EquivalentTo(New("file1")))
313314
require.True(t, wd.Join("file1").EquivalentTo(New("file1", "abc", "..")))
315+
316+
if runtime.GOOS == "windows" {
317+
q := New("_testdata", "anotherFile")
318+
r := New("_testdata", "ANOTHE~1")
319+
require.True(t, q.EquivalentTo(r))
320+
require.True(t, r.EquivalentTo(q))
321+
}
314322
}
315323

316324
func TestRelativeTo(t *testing.T) {

0 commit comments

Comments
 (0)