// See https://golang.org/issues/19922#issuecomment-300031421 for details.
var fa syscall.Win32FileAttributeData
err = syscall.GetFileAttributesEx(namep, syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&fa)))
+ if err == nil && fa.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT == 0 {
+ // Not a surrogate for another named entity, because it isn't any kind of reparse point.
+ // The information we got from GetFileAttributesEx is good enough for now.
+ fs := newFileStatFromWin32FileAttributeData(&fa)
+ if err := fs.saveInfoFromPath(name); err != nil {
+ return nil, err
+ }
+ return fs, nil
+ }
// GetFileAttributesEx fails with ERROR_SHARING_VIOLATION error for
// files like c:\pagefile.sys. Use FindFirstFile for such files.
}
}
- if err == nil && fa.FileAttributes&syscall.FILE_ATTRIBUTE_REPARSE_POINT == 0 {
- // Not a surrogate for another named entity, because it isn't any kind of reparse point.
- // The information we got from GetFileAttributesEx is good enough for now.
- fs := &fileStat{
- FileAttributes: fa.FileAttributes,
- CreationTime: fa.CreationTime,
- LastAccessTime: fa.LastAccessTime,
- LastWriteTime: fa.LastWriteTime,
- FileSizeHigh: fa.FileSizeHigh,
- FileSizeLow: fa.FileSizeLow,
- }
- if err := fs.saveInfoFromPath(name); err != nil {
- return nil, err
- }
- return fs, nil
- }
-
// Use CreateFile to determine whether the file is a name surrogate and, if so,
// save information about the link target.
// Set FILE_FLAG_BACKUP_SEMANTICS so that CreateFile will create the handle
}, nil
}
+// newFileStatFromWin32FileAttributeData copies all required information
+// from syscall.Win32FileAttributeData d into the newly created fileStat.
+func newFileStatFromWin32FileAttributeData(d *syscall.Win32FileAttributeData) *fileStat {
+ return &fileStat{
+ FileAttributes: d.FileAttributes,
+ CreationTime: d.CreationTime,
+ LastAccessTime: d.LastAccessTime,
+ LastWriteTime: d.LastWriteTime,
+ FileSizeHigh: d.FileSizeHigh,
+ FileSizeLow: d.FileSizeLow,
+ }
+}
+
// newFileStatFromFileIDBothDirInfo copies all required information
// from windows.FILE_ID_BOTH_DIR_INFO d into the newly created fileStat.
func newFileStatFromFileIDBothDirInfo(d *windows.FILE_ID_BOTH_DIR_INFO) *fileStat {