github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/os_unix.go (about)

     1  //go:build unix && !sqlite3_nosys
     2  
     3  package vfs
     4  
     5  import (
     6  	"os"
     7  	"syscall"
     8  
     9  	"golang.org/x/sys/unix"
    10  )
    11  
    12  func osAccess(path string, flags AccessFlag) error {
    13  	var access uint32 // unix.F_OK
    14  	switch flags {
    15  	case ACCESS_READWRITE:
    16  		access = unix.R_OK | unix.W_OK
    17  	case ACCESS_READ:
    18  		access = unix.R_OK
    19  	}
    20  	return unix.Access(path, access)
    21  }
    22  
    23  func osSetMode(file *os.File, modeof string) error {
    24  	fi, err := os.Stat(modeof)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	file.Chmod(fi.Mode())
    29  	if sys, ok := fi.Sys().(*syscall.Stat_t); ok {
    30  		file.Chown(int(sys.Uid), int(sys.Gid))
    31  	}
    32  	return nil
    33  }