From: Hiroshi Ioka Date: Tue, 11 Apr 2017 20:34:36 +0000 (+0900) Subject: os: handle relative symlinks starting with slash in Stat on windows X-Git-Tag: go1.9beta1~715 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8a2cc222098539a687accef75f0d1551079ca6c9;p=gostls13.git os: handle relative symlinks starting with slash in Stat on windows https://go-review.googlesource.com/c/39932/ handles relative symlinks. But that change is incomplete. We also have to handle relative symlinks starting with slash too. Fixes #19937 Change-Id: I50dbccbaf270cb48a08fa57e5f450e5da18a7701 Reviewed-on: https://go-review.googlesource.com/40410 Reviewed-by: Alex Brainman Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- diff --git a/src/os/os_test.go b/src/os/os_test.go index 410bfc8007..a7fbfa4cb3 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -1813,6 +1813,23 @@ func TestStatRelativeSymlink(t *testing.T) { if !SameFile(st, st1) { t.Error("Stat doesn't follow relative symlink") } + + if runtime.GOOS == "windows" { + Remove(link) + err = Symlink(target[len(filepath.VolumeName(target)):], link) + if err != nil { + t.Fatal(err) + } + + st1, err := Stat(link) + if err != nil { + t.Fatal(err) + } + + if !SameFile(st, st1) { + t.Error("Stat doesn't follow relative symlink") + } + } } func TestReadAtEOF(t *testing.T) { diff --git a/src/os/stat_windows.go b/src/os/stat_windows.go index 3c640ce992..bcce81cc56 100644 --- a/src/os/stat_windows.go +++ b/src/os/stat_windows.go @@ -75,9 +75,12 @@ func Stat(name string) (FileInfo, error) { if err != nil { return nil, err } - if isAbs(newname) { + switch { + case isAbs(newname): name = newname - } else { + case len(newname) > 0 && IsPathSeparator(newname[0]): + name = volumeName(name) + newname + default: name = dirname(name) + `\` + newname } }