Files
privatae-bastion/client-go/filelock_windows.go
T
Privatae e4c9b69b46
ci / personal-data (push) Successful in 5s
ci / test (push) Successful in 3m4s
ci / fuzz (push) Successful in 3m45s
bastion 0.53.2
2026-10-20 04:42:14 +00:00

26 lines
766 B
Go

//go:build windows
package main
import (
"os"
"golang.org/x/sys/windows"
)
// flockFile takes an exclusive lock on f (blocking) via LockFileEx. Released
// by closing f (Windows releases file locks with the handle).
func flockFile(f *os.File) error {
var ol windows.Overlapped
return windows.LockFileEx(windows.Handle(f.Fd()), windows.LOCKFILE_EXCLUSIVE_LOCK, 0, 1, 0, &ol)
}
// flockFileNB is flockFile without the wait — LOCKFILE_FAIL_IMMEDIATELY. Present
// so the package builds on Windows; the singleton itself is Linux-only today
// (singleton.go).
func flockFileNB(f *os.File) error {
var ol windows.Overlapped
return windows.LockFileEx(windows.Handle(f.Fd()),
windows.LOCKFILE_EXCLUSIVE_LOCK|windows.LOCKFILE_FAIL_IMMEDIATELY, 0, 1, 0, &ol)
}