mirror of
https://github.com/golang/go
synced 2024-11-18 12:44:49 -07:00
os: use FindFirstFile when GetFileAttributesEx fails in Stat
Fixes #15355 Change-Id: Idbab7a627c5de249bb62d519c5a47f3d2f6c82a7 Reviewed-on: https://go-review.googlesource.com/22796 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
abbd502d63
commit
d13fa4d225
@ -7,6 +7,7 @@ package windows
|
||||
import "syscall"
|
||||
|
||||
const (
|
||||
ERROR_SHARING_VIOLATION syscall.Errno = 32
|
||||
ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113
|
||||
)
|
||||
|
||||
|
@ -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 @@
|
||||
package os
|
||||
|
||||
import (
|
||||
"internal/syscall/windows"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
@ -95,7 +96,23 @@ func Lstat(name string) (FileInfo, error) {
|
||||
}
|
||||
e = syscall.GetFileAttributesEx(namep, syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&fs.sys)))
|
||||
if e != nil {
|
||||
return nil, &PathError{"GetFileAttributesEx", name, e}
|
||||
if e != windows.ERROR_SHARING_VIOLATION {
|
||||
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
|
||||
if !isAbs(fs.path) {
|
||||
|
Loading…
Reference in New Issue
Block a user