Files
sqlite3/vfs/os_unix.go

77 lines
1.4 KiB
Go
Raw Normal View History

2024-11-29 15:51:51 +00:00
//go:build unix
2023-01-26 14:52:38 +00:00
2023-06-01 18:11:37 +01:00
package vfs
2023-01-25 14:59:02 +00:00
2023-01-25 16:23:18 +00:00
import (
"os"
2023-06-02 02:31:15 +01:00
"syscall"
2023-03-09 01:59:46 +00:00
"golang.org/x/sys/unix"
2023-01-25 16:23:18 +00:00
)
2023-01-25 14:59:02 +00:00
2025-01-07 16:31:12 +00:00
const (
_O_NOFOLLOW = unix.O_NOFOLLOW
canSyncDirs = true
)
2024-09-27 12:32:11 +01:00
2023-05-19 03:04:07 +01:00
func osAccess(path string, flags AccessFlag) error {
2023-03-23 13:28:25 +00:00
var access uint32 // unix.F_OK
2023-03-09 01:59:46 +00:00
switch flags {
2023-05-19 03:04:07 +01:00
case ACCESS_READWRITE:
2023-03-09 01:59:46 +00:00
access = unix.R_OK | unix.W_OK
2023-05-19 03:04:07 +01:00
case ACCESS_READ:
2023-03-09 01:59:46 +00:00
access = unix.R_OK
}
2023-03-17 17:13:03 +00:00
return unix.Access(path, access)
2023-03-10 14:02:34 +00:00
}
2023-06-02 02:31:15 +01:00
func osSetMode(file *os.File, modeof string) error {
fi, err := os.Stat(modeof)
if err != nil {
return err
}
file.Chmod(fi.Mode())
if sys, ok := fi.Sys().(*syscall.Stat_t); ok {
file.Chown(int(sys.Uid), int(sys.Gid))
}
return nil
}
2024-09-17 23:09:05 +01:00
func osTestLock(file *os.File, start, len int64) (int16, _ErrorCode) {
lock := unix.Flock_t{
Type: unix.F_WRLCK,
Start: start,
Len: len,
}
if unix.FcntlFlock(file.Fd(), unix.F_GETLK, &lock) != nil {
return 0, _IOERR_CHECKRESERVEDLOCK
}
return lock.Type, _OK
}
func osLockErrorCode(err error, def _ErrorCode) _ErrorCode {
if err == nil {
return _OK
}
if errno, ok := err.(unix.Errno); ok {
switch errno {
case
unix.EACCES,
unix.EAGAIN,
unix.EBUSY,
unix.EINTR,
unix.ENOLCK,
unix.EDEADLK,
unix.ETIMEDOUT:
return _BUSY
case unix.EPERM:
return _PERM
}
// notest // usually EWOULDBLOCK == EAGAIN
if errno == unix.EWOULDBLOCK && unix.EWOULDBLOCK != unix.EAGAIN {
return _BUSY
}
}
return def
}