]> Cypherpunks repositories - gostls13.git/commitdiff
os: use Stat instead of Lstat in Symlink
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 26 Oct 2018 07:44:17 +0000 (18:44 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 31 Oct 2018 08:40:43 +0000 (08:40 +0000)
Windows implementation of Symlink uses CreateSymbolicLink Windows
API. The API requires to identify the target type: file or
directory. Current Symlink implementation  uses Lstat to determine
symlink type, but Lstat will not be able to determine correct
result if destination is symlink. Replace Lstat call with Stat.

Fixes #28432

Change-Id: Ibee6d8ac21e2246bf8d0a019c4c66d38b09887d4
Reviewed-on: https://go-review.googlesource.com/c/145217
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/os/file_windows.go
src/os/stat_test.go

index 223698c13016c4e16b46e6f5d54a3ab490cc4d61..7ed4fe2f389d99f6058465a200872b35af3aeffb 100644 (file)
@@ -362,7 +362,7 @@ func Symlink(oldname, newname string) error {
                destpath = dirname(newname) + `\` + oldname
        }
 
-       fi, err := Lstat(destpath)
+       fi, err := Stat(destpath)
        isdir := err == nil && fi.IsDir()
 
        n, err := syscall.UTF16PtrFromString(fixLongPath(newname))
index d59edeb547a166f3f459e0628e66b588561ba40c..da20a4fdbf0d3771bcbd5e5c131f6dd8aa4a7db3 100644 (file)
@@ -205,6 +205,14 @@ func TestDirAndSymlinkStats(t *testing.T) {
        }
        testSymlinkStats(t, dirlink, true)
        testSymlinkSameFile(t, dir, dirlink)
+
+       linklink := filepath.Join(tmpdir, "linklink")
+       err = os.Symlink(dirlink, linklink)
+       if err != nil {
+               t.Fatal(err)
+       }
+       testSymlinkStats(t, linklink, true)
+       testSymlinkSameFile(t, dir, linklink)
 }
 
 func TestFileAndSymlinkStats(t *testing.T) {
@@ -230,6 +238,14 @@ func TestFileAndSymlinkStats(t *testing.T) {
        }
        testSymlinkStats(t, filelink, false)
        testSymlinkSameFile(t, file, filelink)
+
+       linklink := filepath.Join(tmpdir, "linklink")
+       err = os.Symlink(filelink, linklink)
+       if err != nil {
+               t.Fatal(err)
+       }
+       testSymlinkStats(t, linklink, false)
+       testSymlinkSameFile(t, file, linklink)
 }
 
 // see issue 27225 for details