Commit e656aebb authored by Yasuhiro Matsumoto's avatar Yasuhiro Matsumoto Committed by Alex Brainman

os: os: make Stat("*.txt") fail on windows

Fixes #24999

Change-Id: Ie0bb6a6e0fa3992cdd272d42347af65ae7c95463
Reviewed-on: https://go-review.googlesource.com/108755
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAlex Brainman <alex.brainman@gmail.com>
parent a835c739
......@@ -12,6 +12,7 @@ import (
const (
ERROR_SHARING_VIOLATION syscall.Errno = 32
ERROR_INVALID_NAME syscall.Errno = 123
ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113
)
......
......@@ -1055,3 +1055,11 @@ func isWindowsDeveloperModeActive() bool {
return val != 0
}
// TestStatOfInvalidName is regression test for issue #24999.
func TestStatOfInvalidName(t *testing.T) {
_, err := os.Stat("*.go")
if err == nil {
t.Fatal(`os.Stat("*.go") unexpectedly succeeded`)
}
}
......@@ -99,6 +99,14 @@ func newFileStatFromGetFileAttributesExOrFindFirstFile(path string, pathp *uint1
FileSizeLow: fa.FileSizeLow,
}, nil
}
// GetFileAttributesEx returns ERROR_INVALID_NAME if called
// for invalid file name like "*.txt". Do not attempt to call
// FindFirstFile with "*.txt", because FindFirstFile will
// succeed. So just return ERROR_INVALID_NAME instead.
// see https://golang.org/issue/24999 for details.
if errno, _ := err.(syscall.Errno); errno == windows.ERROR_INVALID_NAME {
return nil, &PathError{"GetFileAttributesEx", path, err}
}
// We might have symlink here. But some directories also have
// FileAttributes FILE_ATTRIBUTE_REPARSE_POINT bit set.
// For example, OneDrive directory is like that
......
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