summaryrefslogtreecommitdiff
path: root/vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-12-17 23:16:20 +0000
committerLibravatar GitHub <noreply@github.com>2024-12-17 23:16:20 +0000
commitc953f57e55810fa0e3201a67a4622fe4ac39c278 (patch)
tree6b059966b98e4a687d6d55e98772bd3f7c8b1da7 /vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go
parentbump ncruces/go-sqlite3 to v0.21.1 (#3625) (diff)
downloadgotosocial-c953f57e55810fa0e3201a67a4622fe4ac39c278.tar.xz
update ncruces/go-sqlite3 to v0.21.2 (#3626)
Diffstat (limited to 'vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go')
-rw-r--r--vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go b/vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go
index fa13ef3ae..4f6fadef4 100644
--- a/vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go
+++ b/vendor/github.com/ncruces/go-sqlite3/vfs/os_bsd.go
@@ -9,11 +9,11 @@ import (
)
func osGetSharedLock(file *os.File) _ErrorCode {
- return osLock(file, unix.LOCK_SH|unix.LOCK_NB, _IOERR_RDLOCK)
+ return osFlock(file, unix.LOCK_SH|unix.LOCK_NB, _IOERR_RDLOCK)
}
func osGetReservedLock(file *os.File) _ErrorCode {
- rc := osLock(file, unix.LOCK_EX|unix.LOCK_NB, _IOERR_LOCK)
+ rc := osFlock(file, unix.LOCK_EX|unix.LOCK_NB, _IOERR_LOCK)
if rc == _BUSY {
// The documentation states that a lock is upgraded by
// releasing the previous lock, then acquiring the new lock.
@@ -37,7 +37,7 @@ func osGetExclusiveLock(file *os.File, state *LockLevel) _ErrorCode {
}
func osDowngradeLock(file *os.File, _ LockLevel) _ErrorCode {
- rc := osLock(file, unix.LOCK_SH|unix.LOCK_NB, _IOERR_RDLOCK)
+ rc := osFlock(file, unix.LOCK_SH|unix.LOCK_NB, _IOERR_RDLOCK)
if rc == _BUSY {
// The documentation states that a lock is downgraded by
// releasing the previous lock then acquiring the new lock.
@@ -66,7 +66,36 @@ func osCheckReservedLock(file *os.File) (bool, _ErrorCode) {
return lock == unix.F_WRLCK, rc
}
-func osLock(file *os.File, how int, def _ErrorCode) _ErrorCode {
+func osFlock(file *os.File, how int, def _ErrorCode) _ErrorCode {
err := unix.Flock(int(file.Fd()), how)
return osLockErrorCode(err, def)
}
+
+func osReadLock(file *os.File, start, len int64) _ErrorCode {
+ return osLock(file, unix.F_RDLCK, start, len, _IOERR_RDLOCK)
+}
+
+func osWriteLock(file *os.File, start, len int64) _ErrorCode {
+ return osLock(file, unix.F_WRLCK, start, len, _IOERR_LOCK)
+}
+
+func osLock(file *os.File, typ int16, start, len int64, def _ErrorCode) _ErrorCode {
+ err := unix.FcntlFlock(file.Fd(), unix.F_SETLK, &unix.Flock_t{
+ Type: typ,
+ Start: start,
+ Len: len,
+ })
+ return osLockErrorCode(err, def)
+}
+
+func osUnlock(file *os.File, start, len int64) _ErrorCode {
+ err := unix.FcntlFlock(file.Fd(), unix.F_SETLK, &unix.Flock_t{
+ Type: unix.F_UNLCK,
+ Start: start,
+ Len: len,
+ })
+ if err != nil {
+ return _IOERR_UNLOCK
+ }
+ return _OK
+}