aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYasuhiro Matsumoto <mattn.jp@gmail.com>2018-04-23 13:03:44 +0900
committerAlex Brainman <alex.brainman@gmail.com>2018-04-27 10:04:48 +0000
commite656aebb5b9e0437e050c3050e50a658c0244777 (patch)
treeb565312b24b2506ddda892bd65be12be7350fd6d /src
parenta835c7396d884b29e861594228fac89ba3f0d28d (diff)
downloadgo-e656aebb5b9e0437e050c3050e50a658c0244777.tar.xz
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>
Diffstat (limited to 'src')
-rw-r--r--src/internal/syscall/windows/syscall_windows.go1
-rw-r--r--src/os/os_windows_test.go8
-rw-r--r--src/os/types_windows.go8
3 files changed, 17 insertions, 0 deletions
diff --git a/src/internal/syscall/windows/syscall_windows.go b/src/internal/syscall/windows/syscall_windows.go
index 518af26d72..66fe9324c0 100644
--- a/src/internal/syscall/windows/syscall_windows.go
+++ b/src/internal/syscall/windows/syscall_windows.go
@@ -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
)
diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go
index e28f0f4fa5..8984dd2c66 100644
--- a/src/os/os_windows_test.go
+++ b/src/os/os_windows_test.go
@@ -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`)
+ }
+}
diff --git a/src/os/types_windows.go b/src/os/types_windows.go
index 235b9f1182..f3297c0338 100644
--- a/src/os/types_windows.go
+++ b/src/os/types_windows.go
@@ -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