2023-12-13 14:29:02 +01:00
|
|
|
//go:build windows
|
2022-08-26 22:26:53 +02:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package osfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"golang.org/x/sys/windows"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
kernel32DLL = windows.NewLazySystemDLL("kernel32.dll")
|
|
|
|
lockFileExProc = kernel32DLL.NewProc("LockFileEx")
|
|
|
|
unlockFileProc = kernel32DLL.NewProc("UnlockFile")
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
lockfileExclusiveLock = 0x2
|
|
|
|
)
|
|
|
|
|
|
|
|
func (f *file) Lock() error {
|
|
|
|
f.m.Lock()
|
|
|
|
defer f.m.Unlock()
|
|
|
|
|
|
|
|
var overlapped windows.Overlapped
|
|
|
|
// err is always non-nil as per sys/windows semantics.
|
|
|
|
ret, _, err := lockFileExProc.Call(f.File.Fd(), lockfileExclusiveLock, 0, 0xFFFFFFFF, 0,
|
|
|
|
uintptr(unsafe.Pointer(&overlapped)))
|
|
|
|
runtime.KeepAlive(&overlapped)
|
|
|
|
if ret == 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *file) Unlock() error {
|
|
|
|
f.m.Lock()
|
|
|
|
defer f.m.Unlock()
|
|
|
|
|
|
|
|
// err is always non-nil as per sys/windows semantics.
|
|
|
|
ret, _, err := unlockFileProc.Call(f.File.Fd(), 0, 0, 0xFFFFFFFF, 0)
|
|
|
|
if ret == 0 {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func rename(from, to string) error {
|
|
|
|
return os.Rename(from, to)
|
|
|
|
}
|
2023-12-13 14:29:02 +01:00
|
|
|
|
|
|
|
func umask(new int) func() {
|
|
|
|
return func() {
|
|
|
|
}
|
|
|
|
}
|