//go:build !windows package gitcache import ( "errors" "os" "syscall" ) func lockFile(path string) (*os.File, error) { f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, lockFilePermissions) if err != nil { return nil, err } if err := syscall.Flock(int(f.Fd()), syscall.LOCK_EX|syscall.LOCK_NB); err != nil { _ = f.Close() if errors.Is(err, syscall.EWOULDBLOCK) { return nil, errLocked } return nil, err } return f, nil }