From unknown Mon Jun 23 02:25:44 2025 X-Loop: help-debbugs@gnu.org Subject: bug#27986: 26.0.50; `rename-file' can rename files without confirmation Resent-From: Philipp
Getting back to Philipp's original bug report, Apple docu= mentation says macOS
has a facility like the Linux renameat2 system call (i.e., it's like = 39;renameat'
except it can be told to fail if the destination already exists). Attached = is a
proposed patch to use this facility, which means that the case-insensitivit= y
test would no longer need to be done in macOS. If there's some way to i= mplement
renameat_noreplace on MS-Windows we could get rid of the case-insensitivity= test
there too.
I don't have easy access to macOS so I have not installed this patch. I= t'd be
nice, Philipp, if you could try it out.
RENAME_EXCL
I interpret this such that if the filesystem doesn't su= pport RENAME_EXCL the rename will succeed even if the destination exists.= p>
Since we probably won't be able to solve = all issues across operating systems and filesystems, probably we should hav= e at least a warning in the documentation that rename-file attempts to be r= ace-free and atomic, but only on a best-effort basis.
> From: Paul Eggert <eggert@cs.ucla.edu>
> Cc: Eli Zaretskii <eliz@gnu.org>, 27986@debbugs.gnu.org
> Date: Sun, 13 Aug 2017 16:48:59 -0700
>
> Getting back to Philipp's original bug report, Apple documentation= says macOS
> has a facility like the Linux renameat2 system call (i.e., it's li= ke 'renameat'
> except it can be told to fail if the destination already exists). Atta= ched is a
> proposed patch to use this facility, which means that the case-insensi= tivity
> test would no longer need to be done in macOS. If there's some way= to implement
> renameat_noreplace on MS-Windows we could get rid of the case-insensit= ivity test
> there too.
There's nothing easier than implementing renameat_noreplace on
MS-Windows, since the underlying system call does that by default, and
it's emulating the Posix behavior that requires complications.You might be able to eliminate these complicati= ons by calling MoveFileExW with MOVEFILE_REPLACE_EXISTING.