Commit d13fa4d2 authored by Alex Brainman's avatar Alex Brainman

os: use FindFirstFile when GetFileAttributesEx fails in Stat

Fixes #15355

Change-Id: Idbab7a627c5de249bb62d519c5a47f3d2f6c82a7
Reviewed-on: https://go-review.googlesource.com/22796Reviewed-by: default avatarRuss Cox <rsc@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent abbd502d
...@@ -7,6 +7,7 @@ package windows ...@@ -7,6 +7,7 @@ package windows
import "syscall" import "syscall"
const ( const (
ERROR_SHARING_VIOLATION syscall.Errno = 32
ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113 ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113
) )
......
...@@ -630,3 +630,14 @@ func TestReadStdin(t *testing.T) { ...@@ -630,3 +630,14 @@ func TestReadStdin(t *testing.T) {
} }
} }
} }
func TestStatPagefile(t *testing.T) {
_, err := os.Stat(`c:\pagefile.sys`)
if err == nil {
return
}
if os.IsNotExist(err) {
t.Skip(`skipping because c:\pagefile.sys is not found`)
}
t.Fatal(err)
}
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package os package os
import ( import (
"internal/syscall/windows"
"syscall" "syscall"
"unsafe" "unsafe"
) )
...@@ -95,8 +96,24 @@ func Lstat(name string) (FileInfo, error) { ...@@ -95,8 +96,24 @@ func Lstat(name string) (FileInfo, error) {
} }
e = syscall.GetFileAttributesEx(namep, syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&fs.sys))) e = syscall.GetFileAttributesEx(namep, syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&fs.sys)))
if e != nil { if e != nil {
if e != windows.ERROR_SHARING_VIOLATION {
return nil, &PathError{"GetFileAttributesEx", name, e} return nil, &PathError{"GetFileAttributesEx", name, e}
} }
// try FindFirstFile now that GetFileAttributesEx failed
var fd syscall.Win32finddata
h, e2 := syscall.FindFirstFile(namep, &fd)
if e2 != nil {
return nil, &PathError{"FindFirstFile", name, e}
}
syscall.FindClose(h)
fs.sys.FileAttributes = fd.FileAttributes
fs.sys.CreationTime = fd.CreationTime
fs.sys.LastAccessTime = fd.LastAccessTime
fs.sys.LastWriteTime = fd.LastWriteTime
fs.sys.FileSizeHigh = fd.FileSizeHigh
fs.sys.FileSizeLow = fd.FileSizeLow
}
fs.path = name fs.path = name
if !isAbs(fs.path) { if !isAbs(fs.path) {
fs.path, e = syscall.FullPath(fs.path) fs.path, e = syscall.FullPath(fs.path)
......
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