Skip to content

Commit

Permalink
os: do not report ModeDir for symlinks on windows
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
alexbrainman committed Apr 26, 2017
1 parent 3d86d45 commit 1989921
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 0 additions & 4 deletions src/archive/tar/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"path"
"path/filepath"
"reflect"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions src/os/os_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/os/types_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions src/path/filepath/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
2 changes: 0 additions & 2 deletions src/path/filepath/path_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit 1989921

Please sign in to comment.