aboutsummaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_darwin.go
diff options
context:
space:
mode:
authorSebastian Lackner2017-11-29 12:23:40 +0100
committerSebastian Lackner2017-11-29 12:41:23 +0100
commit0f44c617d01f3e203933459be5fb64c1904d40b6 (patch)
tree14e266ea6e8218d04c58b6dd622ab68810792550 /internal/syscallcompat/sys_darwin.go
parent5d44a31b412e3db07313d3f7e839e2838cff67c0 (diff)
syscallcompat: Introduce unlinkat syscall with flags argument
Diffstat (limited to 'internal/syscallcompat/sys_darwin.go')
-rw-r--r--internal/syscallcompat/sys_darwin.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go
index 4068e1a..527598b 100644
--- a/internal/syscallcompat/sys_darwin.go
+++ b/internal/syscallcompat/sys_darwin.go
@@ -6,6 +6,8 @@ import (
"path/filepath"
"sync"
"syscall"
+
+ "golang.org/x/sys/unix"
)
// Sorry, fallocate is not available on OSX at all and
@@ -71,21 +73,24 @@ func Renameat(olddirfd int, oldpath string, newdirfd int, newpath string) error
}
// Poor man's Unlinkat
-func Unlinkat(dirfd int, path string) error {
+func Unlinkat(dirfd int, path string, flags int) (err error) {
chdirMutex.Lock()
defer chdirMutex.Unlock()
- if !filepath.IsAbs(path) {
- oldWd, err := os.Getwd()
- if err != nil {
- return err
- }
- defer os.Chdir(oldWd)
+ cwd, err := syscall.Open(".", syscall.O_RDONLY, 0)
+ if err != nil {
+ return err
}
- path, err := dirfdAbs(dirfd, path)
+ defer syscall.Close(cwd)
+ err = syscall.Fchdir(dirfd)
if err != nil {
return err
}
- return syscall.Unlink(path)
+ defer syscall.Fchdir(cwd)
+ if (flags & unix.AT_REMOVEDIR) != 0 {
+ return syscall.Rmdir(path)
+ } else {
+ return syscall.Unlink(path)
+ }
}
// Poor man's Mknodat