Files
GaCy-GO/internal/common/persistent_lock_unix.go
T

21 lines
469 B
Go

//go:build linux || darwin || freebsd || openbsd || netbsd || dragonfly
package common
import (
"os"
"syscall"
)
func lockPersistentFile() (func(), error) {
file, err := os.OpenFile("persistent.lock", os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
return nil, err
}
if err := syscall.Flock(int(file.Fd()), syscall.LOCK_EX); err != nil {
file.Close()
return nil, err
}
return func() { syscall.Flock(int(file.Fd()), syscall.LOCK_UN); file.Close() }, nil
}