diff options
author | Jenkins nedprod CI <jenkins-nedprod@europe5.nedproductions.biz> | 2020-07-16 02:00:11 +0300 |
---|---|---|
committer | Jenkins nedprod CI <jenkins-nedprod@europe5.nedproductions.biz> | 2020-07-16 02:00:11 +0300 |
commit | 7d731a07239454c3eb8f18e4c6674ab8873344d5 (patch) | |
tree | 7abf1abe229650a47d3c275f9e0d70b334435e01 | |
parent | 794c13254d2532884d34568a416c097355e8f829 (diff) | |
parent | 6f926dc9e61c9f5231de03c851373c7112f27186 (diff) |
Merged from develop branch as CDash reports all green
-rw-r--r-- | include/llfio/v2.0/detail/impl/posix/fs_handle.ipp | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp b/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp index b17dafc0..8c8d2c14 100644 --- a/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp +++ b/include/llfio/v2.0/detail/impl/posix/fs_handle.ipp @@ -219,23 +219,29 @@ result<void> fs_handle::relink(const path_handle &base, path_view_type path, boo // Linux has an extension for atomic non-replacing renames #ifdef __linux__ errno = 0; - if(-1 != + if(-1 != #if defined __aarch64__ - syscall(276 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 1 /*RENAME_NOREPLACE*/) + syscall(276 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, + 1 /*RENAME_NOREPLACE*/) #elif defined __arm__ - syscall(382 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 1 /*RENAME_NOREPLACE*/) + syscall(382 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, + 1 /*RENAME_NOREPLACE*/) #elif defined __i386__ - syscall(353 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 1 /*RENAME_NOREPLACE*/) + syscall(353 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, + 1 /*RENAME_NOREPLACE*/) #elif defined __powerpc64__ - syscall(357 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 1 /*RENAME_NOREPLACE*/) + syscall(357 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, + 1 /*RENAME_NOREPLACE*/) #elif defined __sparc__ - syscall(345 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 1 /*RENAME_NOREPLACE*/) + syscall(345 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, + 1 /*RENAME_NOREPLACE*/) #elif defined __x86_64__ - syscall(316 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 1 /*RENAME_NOREPLACE*/) + syscall(316 /*__NR_renameat2*/, dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, + 1 /*RENAME_NOREPLACE*/) #else #error Unknown Linux platform #endif - ) + ) { return success(); } @@ -244,12 +250,20 @@ result<void> fs_handle::relink(const path_handle &base, path_view_type path, boo return posix_error(); } #endif - // Otherwise we need to use linkat followed by unlinkat, carefully reopening the file descriptor - // to preserve path tracking +// Otherwise we need to use linkat followed by unlinkat, carefully reopening the file descriptor +// to preserve path tracking if(-1 == ::linkat(dirh.native_handle().fd, filename.c_str(), base.is_valid() ? base.native_handle().fd : AT_FDCWD, zpath.buffer, 0)) { return posix_error(); } +#ifdef __APPLE__ + // Apple randomly loses link tracking if you open a file with more than + // one hard link, so we unlink before opening the handle + if(-1 == ::unlinkat(dirh.native_handle().fd, filename.c_str(), 0)) + { + return posix_error(); + } +#endif int attribs = fcntl(h.native_handle().fd, F_GETFL); int errcode = errno; if(-1 != attribs) @@ -290,10 +304,12 @@ result<void> fs_handle::relink(const path_handle &base, path_view_type path, boo errcode = 0; } } +#ifndef __APPLE__ if(-1 == ::unlinkat(dirh.native_handle().fd, filename.c_str(), 0)) { return posix_error(); } +#endif if(errcode != 0) { return posix_error(errcode); |