syscallcompat: add Renameat2 for Darwin

This commit is contained in:
Jakob Unterwurzacher 2020-09-09 11:16:29 +02:00
parent 7c0363dee5
commit 8b1df08b8a
2 changed files with 19 additions and 3 deletions

View File

@ -21,6 +21,9 @@ const (
// O_PATH is only defined on Linux
O_PATH = 0
// RENAME_NOREPLACE is only defined on Linux
RENAME_NOREPLACE = 0
// KAUTH_UID_NONE and KAUTH_GID_NONE are special values to
// revert permissions to the process credentials.
KAUTH_UID_NONE = ^uint32(0) - 100
@ -131,12 +134,12 @@ func SymlinkatUser(oldpath string, newdirfd int, newpath string, context *fuse.C
return Symlinkat(oldpath, newdirfd, newpath)
}
func MkdiratUser(dirfd int, path string, mode uint32, context *fuse.Context) (err error) {
if context != nil {
func MkdiratUser(dirfd int, path string, mode uint32, caller *fuse.Caller) (err error) {
if caller != nil {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
err = pthread_setugid_np(context.Owner.Uid, context.Owner.Gid)
err = pthread_setugid_np(caller.Uid, caller.Gid)
if err != nil {
return err
}
@ -215,3 +218,8 @@ func UtimesNanoAtNofollow(dirfd int, path string, a *time.Time, m *time.Time) (e
func Getdents(fd int) ([]fuse.DirEntry, error) {
return emulateGetdents(fd)
}
// Renameat2 does not exist on Darwin, so we call Renameat and ignore the flags.
func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) {
return unix.Renameat(olddirfd, oldpath, newdirfd, newpath)
}

View File

@ -27,6 +27,9 @@ const (
// O_PATH is only defined on Linux
O_PATH = unix.O_PATH
// RENAME_NOREPLACE is only defined on Linux
RENAME_NOREPLACE = unix.RENAME_NOREPLACE
)
var preallocWarn sync.Once
@ -271,3 +274,8 @@ func UtimesNanoAtNofollow(dirfd int, path string, a *time.Time, m *time.Time) (e
func Getdents(fd int) ([]fuse.DirEntry, error) {
return getdents(fd)
}
// Renameat2 does not exist on Darwin, so we have to wrap it here.
func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) {
return unix.Renameat2(olddirfd, oldpath, newdirfd, newpath, flags)
}