Skip to content

Commit 8998046

Browse files
committed
Treat junctions as symlinks
1 parent e55a933 commit 8998046

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

internal/vfs/symlink.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313
"syscall"
1414
)
1515

16+
// This is a copy of filepath.EvalSymlinks, but treats junctions as symlinks, matching pre-Go 1.23 behavior.
17+
1618
func volumeNameLen(path string) int {
1719
return len(filepath.VolumeName(path))
1820
}
@@ -91,7 +93,7 @@ func walkSymlinks(path string) (string, error) {
9193
return "", err
9294
}
9395

94-
if fi.Mode()&fs.ModeSymlink == 0 {
96+
if fi.Mode()&fs.ModeSymlink == 0 && !isJunction(fi) {
9597
if !fi.Mode().IsDir() && end < len(path) {
9698
return "", syscall.ENOTDIR
9799
}

internal/vfs/symlink_other.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build !windows
2+
3+
package vfs
4+
5+
import "os"
6+
7+
func isJunction(fi os.FileInfo) bool {
8+
return false
9+
}

internal/vfs/symlink_windows.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package vfs
2+
3+
import (
4+
"os"
5+
"syscall"
6+
)
7+
8+
func isJunction(fi os.FileInfo) bool {
9+
sys := fi.Sys().(*syscall.Win32FileAttributeData)
10+
return sys.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 && sys.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0
11+
}

0 commit comments

Comments
 (0)