diff options
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/stat_test.go | 7 | ||||
| -rw-r--r-- | src/os/stat_windows.go | 11 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/os/stat_test.go b/src/os/stat_test.go index 72621f257b..96019699aa 100644 --- a/src/os/stat_test.go +++ b/src/os/stat_test.go @@ -9,7 +9,6 @@ import ( "io/fs" "os" "path/filepath" - "runtime" "testing" ) @@ -279,11 +278,7 @@ func TestSymlinkWithTrailingSlash(t *testing.T) { } dirlinkWithSlash := dirlink + string(os.PathSeparator) - if runtime.GOOS == "windows" { - testSymlinkStats(t, dirlinkWithSlash, true) - } else { - testDirStats(t, dirlinkWithSlash) - } + testDirStats(t, dirlinkWithSlash) fi1, err := os.Stat(dir) if err != nil { diff --git a/src/os/stat_windows.go b/src/os/stat_windows.go index 7ac9f7b860..033c3b9353 100644 --- a/src/os/stat_windows.go +++ b/src/os/stat_windows.go @@ -123,5 +123,14 @@ func statNolog(name string) (FileInfo, error) { // lstatNolog implements Lstat for Windows. func lstatNolog(name string) (FileInfo, error) { - return stat("Lstat", name, false) + followSymlinks := false + if name != "" && IsPathSeparator(name[len(name)-1]) { + // We try to implement POSIX semantics for Lstat path resolution + // (per https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/basedefs/V1_chap04.html#tag_04_12): + // symlinks before the last separator in the path must be resolved. Since + // the last separator in this case follows the last path element, we should + // follow symlinks in the last path element. + followSymlinks = true + } + return stat("Lstat", name, followSymlinks) } |
