Commit 1989921a authored by Alex Brainman's avatar Alex Brainman

os: do not report ModeDir for symlinks on windows

When using Lstat against symlinks that point to a directory,
the function returns FileInfo with both ModeDir and ModeSymlink set.
Change that to never set ModeDir if ModeSymlink is set.

Fixes #10424
Fixes #17540
Fixes #17541

Change-Id: Iba280888aad108360b8c1f18180a24493fe7ad2b
Reviewed-on: https://go-review.googlesource.com/41830Reviewed-by: 's avatarDaniel Martí <mvdan@mvdan.cc>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 3d86d45d
......@@ -12,7 +12,6 @@ import (
"path"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
"time"
......@@ -72,9 +71,6 @@ func TestFileInfoHeaderDir(t *testing.T) {
func TestFileInfoHeaderSymlink(t *testing.T) {
testenv.MustHaveSymlink(t)
if runtime.GOOS == "windows" {
t.Skip("skipping broken test: see issue 17541")
}
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink")
if err != nil {
t.Fatal(err)
......
......@@ -153,6 +153,20 @@ func testDirLinks(t *testing.T, tests []dirLinkTest) {
t.Errorf("%q should point to %q", link, dir)
continue
}
fi2, err := os.Lstat(link)
if err != nil {
t.Errorf("failed to lstat link %v: %v", link, err)
continue
}
if m := fi2.Mode(); m&os.ModeSymlink == 0 {
t.Errorf("%q should be a link, but is not (mode=0x%x)", link, uint32(m))
continue
}
if m := fi2.Mode(); m&os.ModeDir != 0 {
t.Errorf("%q should be a link, not a directory (mode=0x%x)", link, uint32(m))
continue
}
}
}
......
......@@ -32,16 +32,16 @@ func (fs *fileStat) Mode() (m FileMode) {
if fs == &devNullStat {
return ModeDevice | ModeCharDevice | 0666
}
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
m |= ModeDir | 0111
}
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_READONLY != 0 {
m |= 0444
} else {
m |= 0666
}
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 {
m |= ModeSymlink
return m | ModeSymlink
}
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
m |= ModeDir | 0111
}
switch fs.filetype {
case syscall.FILE_TYPE_PIPE:
......
......@@ -1377,8 +1377,5 @@ func testWalkSymlink(t *testing.T, mklink func(target, link string) error) {
func TestWalkSymlink(t *testing.T) {
testenv.MustHaveSymlink(t)
if runtime.GOOS == "windows" {
t.Skip("skipping broken test: see issue 17540")
}
testWalkSymlink(t, os.Symlink)
}
......@@ -451,12 +451,10 @@ func testWalkMklink(t *testing.T, linktype string) {
func TestWalkDirectoryJunction(t *testing.T) {
testenv.MustHaveSymlink(t)
t.Skip("skipping broken test: see issue 10424")
testWalkMklink(t, "J")
}
func TestWalkDirectorySymlink(t *testing.T) {
testenv.MustHaveSymlink(t)
t.Skip("skipping broken test: see issue 17540")
testWalkMklink(t, "D")
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment