bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] renameatu: work around macOS 11.2 renameatx_np bug


From: Paul Eggert
Subject: [PATCH] renameatu: work around macOS 11.2 renameatx_np bug
Date: Wed, 24 Mar 2021 20:42:29 -0700

* lib/renameatu.c (renameatu) [RENAME_EXCL]: Use lstatat test here too.
---
 ChangeLog       | 5 +++++
 lib/renameatu.c | 7 ++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index b2004479a..af9eb725c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2021-03-24  Paul Eggert  <eggert@cs.ucla.edu>
+
+       renameatu: work around macOS 11.2 renameatx_np bug
+       * lib/renameatu.c (renameatu) [RENAME_EXCL]: Use lstatat test here too.
+
 2021-03-22  Bruno Haible  <bruno@clisp.org>
 
        clean-temp-simple: Fix a rare memory leak.
diff --git a/lib/renameatu.c b/lib/renameatu.c
index c493a38dc..38438a4ef 100644
--- a/lib/renameatu.c
+++ b/lib/renameatu.c
@@ -122,18 +122,19 @@ renameatu (int fd1, char const *src, int fd2, char const 
*dst,
             | (flags & RENAME_NOREPLACE ? RENAME_EXCL : 0));
 # endif
 
-# if !defined RENAME_EXCL
   if ((flags & RENAME_NOREPLACE) != 0)
     {
       /* This has a race between the call to lstatat and the calls to
-         renameat below.  */
+         renameat below.  This lstatat is needed even if RENAME_EXCL
+         is defined, because RENAME_EXCL is buggy on macOS 11.2:
+         renameatx_np (fd, "X", fd, "X", RENAME_EXCL) incorrectly
+         succeeds when X exists.  */
       if (lstatat (fd2, dst, &dst_st) == 0 || errno == EOVERFLOW)
         return errno_fail (EEXIST);
       if (errno != ENOENT)
         return -1;
       dst_found_nonexistent = true;
     }
-# endif
 
   /* Let strace see any ENOENT failure.  */
   src_len = strlen (src);
-- 
2.27.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]