31 lines
726 B
Go
31 lines
726 B
Go
//go:build windows
|
|
|
|
package state
|
|
|
|
import (
|
|
"os"
|
|
"runtime"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
var lockFileEx = syscall.NewLazyDLL("kernel32.dll").NewProc("LockFileEx")
|
|
|
|
func lockExclusive(f *os.File) error {
|
|
var overlapped syscall.Overlapped
|
|
// LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK, first byte only.
|
|
ok, _, err := lockFileEx.Call(f.Fd(), 3, 0, 1, 0, uintptr(unsafe.Pointer(&overlapped)))
|
|
runtime.KeepAlive(f)
|
|
if ok != 0 {
|
|
return nil
|
|
}
|
|
if err == syscall.Errno(33) {
|
|
return ErrBusy
|
|
}
|
|
return err
|
|
}
|
|
|
|
// Windows is a development platform. File.Sync is used, but Go does not provide
|
|
// a portable directory fsync here. Do not claim Windows power-loss durability.
|
|
func syncDirectory(*os.Root) error { return nil }
|