mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-26 18:22:09 +02:00
Remove use of syscall package for flock
It is provided by unix package these days
This commit is contained in:
@@ -3,27 +3,29 @@
|
|||||||
package utils
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"syscall"
|
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = fmt.Print
|
var _ = fmt.Print
|
||||||
|
|
||||||
func lock(fd, op int, path string) (err error) {
|
func lock(fd, op int, path string) (err error) {
|
||||||
for {
|
for {
|
||||||
err = syscall.Flock(fd, op)
|
err = unix.Flock(fd, op)
|
||||||
if err != syscall.EINTR {
|
if !errors.Is(err, unix.EINTR) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
opname := "exclusive flock()"
|
opname := "exclusive flock()"
|
||||||
switch op {
|
switch op {
|
||||||
case syscall.LOCK_UN:
|
case unix.LOCK_UN:
|
||||||
opname = "unlock flock()"
|
opname = "unlock flock()"
|
||||||
case syscall.LOCK_SH:
|
case unix.LOCK_SH:
|
||||||
opname = "shared flock()"
|
opname = "shared flock()"
|
||||||
}
|
}
|
||||||
return &fs.PathError{
|
return &fs.PathError{
|
||||||
@@ -36,13 +38,13 @@ func lock(fd, op int, path string) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func LockFileShared(f *os.File) error {
|
func LockFileShared(f *os.File) error {
|
||||||
return lock(int(f.Fd()), syscall.LOCK_SH, f.Name())
|
return lock(int(f.Fd()), unix.LOCK_SH, f.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
func LockFileExclusive(f *os.File) error {
|
func LockFileExclusive(f *os.File) error {
|
||||||
return lock(int(f.Fd()), syscall.LOCK_EX, f.Name())
|
return lock(int(f.Fd()), unix.LOCK_EX, f.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
func UnlockFile(f *os.File) error {
|
func UnlockFile(f *os.File) error {
|
||||||
return lock(int(f.Fd()), syscall.LOCK_UN, f.Name())
|
return lock(int(f.Fd()), unix.LOCK_UN, f.Name())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user