]> Savannah Git Hosting - gnulib.git/commitdiff
renameatu: work around macOS 11.2 renameatx_np bug
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 25 Mar 2021 03:40:46 +0000 (20:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 25 Mar 2021 03:42:16 +0000 (20:42 -0700)
* lib/renameatu.c (renameatu) [RENAME_EXCL]: Use lstatat test here too.

ChangeLog
lib/renameatu.c

index b2004479a23a582fedc1b4f3114e2b5a9759a8d9..af9eb725cba9af0831edfcecf3a2468cd7d1ae11 100644 (file)
--- 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.
index c493a38dc1f387cddb1440ed4a8cb26cc0d01d7f..38438a4ef11cca8fab3b18c3385e3d632c4ac058 100644 (file)
@@ -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);