]> Cypherpunks repositories - gostls13.git/commitdiff
os: handle relative symlinks starting with slash in Stat on windows
authorHiroshi Ioka <hirochachacha@gmail.com>
Tue, 11 Apr 2017 20:34:36 +0000 (05:34 +0900)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 12 Apr 2017 23:33:11 +0000 (23:33 +0000)
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 <alex.brainman@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/os/os_test.go
src/os/stat_windows.go

index 410bfc8007076855cb4fc8437c4695581e55e477..a7fbfa4cb3fbf58d33b83570b45265e3c42aca56 100644 (file)
@@ -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) {
index 3c640ce992c904285982b05b659a8a0c3858d32f..bcce81cc56c4336ddf30e1d857df0578ca2e361c 100644 (file)
@@ -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
                }
        }