mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-11-23 20:26:39 +00:00
37 lines
496 B
Go
37 lines
496 B
Go
|
//go:build !unix || sqlite3_nosys
|
||
|
|
||
|
package vfs
|
||
|
|
||
|
import (
|
||
|
"io/fs"
|
||
|
"os"
|
||
|
)
|
||
|
|
||
|
func osAccess(path string, flags AccessFlag) error {
|
||
|
fi, err := os.Stat(path)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
if flags == ACCESS_EXISTS {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
S_IREAD = 0400
|
||
|
S_IWRITE = 0200
|
||
|
S_IEXEC = 0100
|
||
|
)
|
||
|
|
||
|
var want fs.FileMode = S_IREAD
|
||
|
if flags == ACCESS_READWRITE {
|
||
|
want |= S_IWRITE
|
||
|
}
|
||
|
if fi.IsDir() {
|
||
|
want |= S_IEXEC
|
||
|
}
|
||
|
if fi.Mode()&want != want {
|
||
|
return fs.ErrPermission
|
||
|
}
|
||
|
return nil
|
||
|
}
|