summaryrefslogtreecommitdiff
path: root/internal/syscallcompat/sys_darwin.go
diff options
context:
space:
mode:
authorrafjaf2025-07-20 18:24:34 +0200
committerJakob Unterwurzacher2025-08-07 23:06:03 +0200
commitf59e552e755f35c0278eaebd27a0dacb10914551 (patch)
treefb7305584a724c17630c92dcec2ea8ba7df9706c /internal/syscallcompat/sys_darwin.go
parent2ebd0d754b8ee46e6c65e90e1d1e13491b03b7b5 (diff)
darwin: syscallcompat: add RenameatxNp plus flags
Fix macos file saving problem by implementing RENAME_EXCHANGE flag. With test. The dummy value for RENAME_WHITEOUT collides with the new flags. Move it wayyy up. https://github.com/rfjakob/gocryptfs/issues/914
Diffstat (limited to 'internal/syscallcompat/sys_darwin.go')
-rw-r--r--internal/syscallcompat/sys_darwin.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/internal/syscallcompat/sys_darwin.go b/internal/syscallcompat/sys_darwin.go
index cf2f3f0..0ebdd3b 100644
--- a/internal/syscallcompat/sys_darwin.go
+++ b/internal/syscallcompat/sys_darwin.go
@@ -20,11 +20,13 @@ const (
// O_PATH is only defined on Linux
O_PATH = 0
+ // Same meaning, different name
+ RENAME_NOREPLACE = unix.RENAME_EXCL
+ RENAME_EXCHANGE = unix.RENAME_SWAP
+
// Only exists on Linux. Define here to fix build failure, even though
- // we will never see the flags.
- RENAME_NOREPLACE = 1
- RENAME_EXCHANGE = 2
- RENAME_WHITEOUT = 4
+ // we will never see this flag.
+ RENAME_WHITEOUT = 1 << 30
)
// Unfortunately fsetattrlist does not have a syscall wrapper yet.
@@ -152,7 +154,12 @@ func GetdentsSpecial(fd int) (entries []fuse.DirEntry, entriesSpecial []fuse.Dir
return emulateGetdents(fd)
}
-// Renameat2 does not exist on Darwin, so we call Renameat and ignore the flags.
+// Renameat2 does not exist on Darwin, but RenameatxNp does.
func Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error) {
- return unix.Renameat(olddirfd, oldpath, newdirfd, newpath)
+ // If no flags are set, use tried and true renameat
+ if flags == 0 {
+ return unix.Renameat(olddirfd, oldpath, newdirfd, newpath)
+ }
+ // Let RenameatxNp handle everything else
+ return unix.RenameatxNp(olddirfd, oldpath, newdirfd, newpath, uint32(flags))
}