github.com/ncruces/go-sqlite3@v0.15.1-0.20240520133447-53eef1510ff0/vfs/os_std_access.go (about) 1 //go:build !unix || sqlite3_nosys 2 3 package vfs 4 5 import ( 6 "io/fs" 7 "os" 8 ) 9 10 func osAccess(path string, flags AccessFlag) error { 11 fi, err := os.Stat(path) 12 if err != nil { 13 return err 14 } 15 if flags == ACCESS_EXISTS { 16 return nil 17 } 18 19 const ( 20 S_IREAD = 0400 21 S_IWRITE = 0200 22 S_IEXEC = 0100 23 ) 24 25 var want fs.FileMode = S_IREAD 26 if flags == ACCESS_READWRITE { 27 want |= S_IWRITE 28 } 29 if fi.IsDir() { 30 want |= S_IEXEC 31 } 32 if fi.Mode()&want != want { 33 return fs.ErrPermission 34 } 35 return nil 36 }