mirror of
https://github.com/golang/go
synced 2024-11-12 09:20:22 -07:00
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: Alex Brainman <alex.brainman@gmail.com>
This commit is contained in:
parent
a835c7396d
commit
e656aebb5b
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user