From: Paul Eggert Date: Mon, 14 Aug 2017 22:25:13 +0000 (-0700) Subject: Improve rename-file behavior on macOS X-Git-Tag: emacs-26.0.90~461 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=13a846823a92447d5cf0c2ce2bb401c5cdcb9ee4;p=emacs.git Improve rename-file behavior on macOS Problem reported by Philipp Stephani (Bug#27986). * src/fileio.c (Frename_file): Worry about file name case sensitivity only if CYGWIN or DOS_NT. * src/sysdep.c (renameat_noreplace): Use renameatx_np on macOS, since this provides the necessary atomicity guarantees. --- diff --git a/src/fileio.c b/src/fileio.c index 69079c6ae49..9f6de5b6ca7 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -2259,12 +2259,14 @@ This is what happens in interactive use with M-x. */) not worry whether NEWNAME exists or whether it is a directory, as it is already another name for FILE. */ bool case_only_rename = false; +#if defined CYGWIN || defined DOS_NT if (!NILP (Ffile_name_case_insensitive_p (file))) { newname = Fexpand_file_name (newname, Qnil); case_only_rename = !NILP (Fstring_equal (Fdowncase (file), Fdowncase (newname))); } +#endif if (!case_only_rename) newname = expand_cp_target (Fdirectory_file_name (file), newname); diff --git a/src/sysdep.c b/src/sysdep.c index 35f499c1853..2e18a419e3f 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2693,11 +2693,13 @@ renameat_noreplace (int srcfd, char const *src, int dstfd, char const *dst) { #if defined SYS_renameat2 && defined RENAME_NOREPLACE return syscall (SYS_renameat2, srcfd, src, dstfd, dst, RENAME_NOREPLACE); +#elif defined RENAME_EXCL + return renameatx_np (srcfd, src, dstfd, dst, RENAME_EXCL); #else -#ifdef WINDOWSNT +# ifdef WINDOWSNT if (srcfd == AT_FDCWD && dstfd == AT_FDCWD) return sys_rename_replace (src, dst, 0); -#endif +# endif errno = ENOSYS; return -1; #endif