mirror of
https://github.com/ncruces/go-sqlite3.git
synced 2026-01-12 14:09:13 +00:00
50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
package sqlite3
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"golang.org/x/sys/unix"
|
|
)
|
|
|
|
func (vfsOSMethods) Sync(file *os.File, fullsync, dataonly bool) error {
|
|
if dataonly {
|
|
//lint:ignore SA1019 OK on linux
|
|
_, _, err := unix.Syscall(unix.SYS_FDATASYNC, file.Fd(), 0, 0)
|
|
if err != 0 {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|
|
return file.Sync()
|
|
}
|
|
|
|
func (vfsOSMethods) Allocate(file *os.File, size int64) error {
|
|
if size == 0 {
|
|
return nil
|
|
}
|
|
return unix.Fallocate(int(file.Fd()), 0, 0, size)
|
|
}
|
|
|
|
func (vfsOSMethods) fcntlGetLock(file *os.File, lock *unix.Flock_t) error {
|
|
return unix.FcntlFlock(file.Fd(), unix.F_OFD_GETLK, lock)
|
|
}
|
|
|
|
func (vfsOSMethods) fcntlSetLock(file *os.File, lock unix.Flock_t) error {
|
|
return unix.FcntlFlock(file.Fd(), unix.F_OFD_SETLK, &lock)
|
|
}
|
|
|
|
func (vfsOSMethods) fcntlSetLockTimeout(file *os.File, lock unix.Flock_t, timeout time.Duration) error {
|
|
for {
|
|
err := unix.FcntlFlock(file.Fd(), unix.F_OFD_SETLK, &lock)
|
|
if errno, _ := err.(unix.Errno); errno != unix.EAGAIN {
|
|
return err
|
|
}
|
|
if timeout < time.Millisecond {
|
|
return err
|
|
}
|
|
timeout -= time.Millisecond
|
|
time.Sleep(time.Millisecond)
|
|
}
|
|
}
|