Skip to content

Commit 1989921

Browse files
committed
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/41830 Reviewed-by: Daniel Martí <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 3d86d45 commit 1989921

File tree

5 files changed

+18
-13
lines changed

5 files changed

+18
-13
lines changed

src/archive/tar/tar_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"path"
1313
"path/filepath"
1414
"reflect"
15-
"runtime"
1615
"strings"
1716
"testing"
1817
"time"
@@ -72,9 +71,6 @@ func TestFileInfoHeaderDir(t *testing.T) {
7271
func TestFileInfoHeaderSymlink(t *testing.T) {
7372
testenv.MustHaveSymlink(t)
7473

75-
if runtime.GOOS == "windows" {
76-
t.Skip("skipping broken test: see issue 17541")
77-
}
7874
tmpdir, err := ioutil.TempDir("", "TestFileInfoHeaderSymlink")
7975
if err != nil {
8076
t.Fatal(err)

src/os/os_windows_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,20 @@ func testDirLinks(t *testing.T, tests []dirLinkTest) {
153153
t.Errorf("%q should point to %q", link, dir)
154154
continue
155155
}
156+
157+
fi2, err := os.Lstat(link)
158+
if err != nil {
159+
t.Errorf("failed to lstat link %v: %v", link, err)
160+
continue
161+
}
162+
if m := fi2.Mode(); m&os.ModeSymlink == 0 {
163+
t.Errorf("%q should be a link, but is not (mode=0x%x)", link, uint32(m))
164+
continue
165+
}
166+
if m := fi2.Mode(); m&os.ModeDir != 0 {
167+
t.Errorf("%q should be a link, not a directory (mode=0x%x)", link, uint32(m))
168+
continue
169+
}
156170
}
157171
}
158172

src/os/types_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ func (fs *fileStat) Mode() (m FileMode) {
3232
if fs == &devNullStat {
3333
return ModeDevice | ModeCharDevice | 0666
3434
}
35-
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
36-
m |= ModeDir | 0111
37-
}
3835
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_READONLY != 0 {
3936
m |= 0444
4037
} else {
4138
m |= 0666
4239
}
4340
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT != 0 {
44-
m |= ModeSymlink
41+
return m | ModeSymlink
42+
}
43+
if fs.sys.FileAttributes&syscall.FILE_ATTRIBUTE_DIRECTORY != 0 {
44+
m |= ModeDir | 0111
4545
}
4646
switch fs.filetype {
4747
case syscall.FILE_TYPE_PIPE:

src/path/filepath/path_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1377,8 +1377,5 @@ func testWalkSymlink(t *testing.T, mklink func(target, link string) error) {
13771377

13781378
func TestWalkSymlink(t *testing.T) {
13791379
testenv.MustHaveSymlink(t)
1380-
if runtime.GOOS == "windows" {
1381-
t.Skip("skipping broken test: see issue 17540")
1382-
}
13831380
testWalkSymlink(t, os.Symlink)
13841381
}

src/path/filepath/path_windows_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,12 +451,10 @@ func testWalkMklink(t *testing.T, linktype string) {
451451

452452
func TestWalkDirectoryJunction(t *testing.T) {
453453
testenv.MustHaveSymlink(t)
454-
t.Skip("skipping broken test: see issue 10424")
455454
testWalkMklink(t, "J")
456455
}
457456

458457
func TestWalkDirectorySymlink(t *testing.T) {
459458
testenv.MustHaveSymlink(t)
460-
t.Skip("skipping broken test: see issue 17540")
461459
testWalkMklink(t, "D")
462460
}

0 commit comments

Comments
 (0)