Skip to content

Commit

Permalink
os: handle relative symlinks starting with slash in Stat on windows
Browse files Browse the repository at this point in the history
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 golang#19937

Change-Id: I50dbccbaf270cb48a08fa57e5f450e5da18a7701
Reviewed-on: https://go-review.googlesource.com/40410
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
  • Loading branch information
hirochachacha authored and lparth committed Apr 13, 2017
1 parent e4b1a3b commit 2bf284e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/os/os_test.go
Expand Up @@ -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) {
Expand Down
7 changes: 5 additions & 2 deletions src/os/stat_windows.go
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 2bf284e

Please sign in to comment.