33 lines
770 B
Go
33 lines
770 B
Go
//go:build windows
|
|
|
|
package main
|
|
|
|
import (
|
|
"os"
|
|
"syscall"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func openRecord(path string) (*os.File, error) {
|
|
name, err := windows.UTF16PtrFromString(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
handle, err := windows.CreateFile(name, windows.GENERIC_READ, windows.FILE_SHARE_READ,
|
|
nil, windows.OPEN_EXISTING, windows.FILE_FLAG_OPEN_REPARSE_POINT, 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
var data windows.ByHandleFileInformation
|
|
if err := windows.GetFileInformationByHandle(handle, &data); err != nil {
|
|
windows.CloseHandle(handle)
|
|
return nil, err
|
|
}
|
|
if data.FileAttributes&windows.FILE_ATTRIBUTE_REPARSE_POINT != 0 {
|
|
windows.CloseHandle(handle)
|
|
return nil, syscall.EINVAL
|
|
}
|
|
return os.NewFile(uintptr(handle), path), nil
|
|
}
|