diff options
| author | Alex Brainman <alex.brainman@gmail.com> | 2018-10-26 18:44:17 +1100 |
|---|---|---|
| committer | Alex Brainman <alex.brainman@gmail.com> | 2018-10-31 08:40:43 +0000 |
| commit | 5cc80899486027db5f0de00870f1e022e1cfb9c5 (patch) | |
| tree | 63692f82b78efe5cf629258f7e3c1f4e5dd4121d /src | |
| parent | fde4b9ed14e339b5064373c1d4a73e211ec32ac4 (diff) | |
| download | go-5cc80899486027db5f0de00870f1e022e1cfb9c5.tar.xz | |
os: use Stat instead of Lstat in Symlink
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>
Diffstat (limited to 'src')
| -rw-r--r-- | src/os/file_windows.go | 2 | ||||
| -rw-r--r-- | src/os/stat_test.go | 16 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/os/file_windows.go b/src/os/file_windows.go index 223698c130..7ed4fe2f38 100644 --- a/src/os/file_windows.go +++ b/src/os/file_windows.go @@ -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)) diff --git a/src/os/stat_test.go b/src/os/stat_test.go index d59edeb547..da20a4fdbf 100644 --- a/src/os/stat_test.go +++ b/src/os/stat_test.go @@ -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 |
