Skip to content

Commit 8a2cc22

Browse files
hirochachachaalexbrainman
authored andcommitted
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 <[email protected]> Run-TryBot: Alex Brainman <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3692925 commit 8a2cc22

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/os/os_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,6 +1813,23 @@ func TestStatRelativeSymlink(t *testing.T) {
18131813
if !SameFile(st, st1) {
18141814
t.Error("Stat doesn't follow relative symlink")
18151815
}
1816+
1817+
if runtime.GOOS == "windows" {
1818+
Remove(link)
1819+
err = Symlink(target[len(filepath.VolumeName(target)):], link)
1820+
if err != nil {
1821+
t.Fatal(err)
1822+
}
1823+
1824+
st1, err := Stat(link)
1825+
if err != nil {
1826+
t.Fatal(err)
1827+
}
1828+
1829+
if !SameFile(st, st1) {
1830+
t.Error("Stat doesn't follow relative symlink")
1831+
}
1832+
}
18161833
}
18171834

18181835
func TestReadAtEOF(t *testing.T) {

src/os/stat_windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,12 @@ func Stat(name string) (FileInfo, error) {
7575
if err != nil {
7676
return nil, err
7777
}
78-
if isAbs(newname) {
78+
switch {
79+
case isAbs(newname):
7980
name = newname
80-
} else {
81+
case len(newname) > 0 && IsPathSeparator(newname[0]):
82+
name = volumeName(name) + newname
83+
default:
8184
name = dirname(name) + `\` + newname
8285
}
8386
}

0 commit comments

Comments
 (0)