-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathfsutils_windows.go
More file actions
39 lines (33 loc) · 1.18 KB
/
fsutils_windows.go
File metadata and controls
39 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package phpstore
import (
"errors"
"os"
"path/filepath"
"syscall"
)
// Taken from https://github.com/golangci/golangci-lint/blob/main/pkg/fsutils/fsutils_windows.go
// This is a workaround for the behavior of [filepath.EvalSymlinks],
// which fails with [syscall.ENOTDIR] if the specified path contains a junction on Windows.
// Junctions can occur, for example, when a volume is mounted as a subdirectory inside another drive.
// This can usually happen when using the Dev Drives feature and replacing existing directories.
// See: https://github.com/golang/go/issues/40180
//
// Since [syscall.ENOTDIR] is only returned when calling [filepath.EvalSymlinks] on Windows
// if part of the presented path is a junction and nothing before was a symlink,
// we simply treat this as NOT symlink,
// because a symlink over the junction makes no sense at all.
func evalSymlinks(path string) (string, error) {
resolved, err := filepath.EvalSymlinks(path)
if err == nil {
return resolved, nil
}
if !errors.Is(err, syscall.ENOTDIR) {
return "", err
}
_, err = os.Stat(path)
if err != nil {
return "", err
}
// If exists, we make the path cleaned before being used
return filepath.Abs(path)
}