From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#27986: 26.0.50; 'rename-file' can rename files without confirmation Date: Sun, 13 Aug 2017 16:48:59 -0700 Organization: UCLA Computer Science Department Message-ID: <0e80a1cf-8217-9e9a-a00f-9fdbd6575fc4@cs.ucla.edu> References: <61980dde-3d68-7200-e7f4-98f62e410060@cs.ucla.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------B763E56ED065112B24927F91" X-Trace: blaine.gmane.org 1502668214 28584 195.159.176.226 (13 Aug 2017 23:50:14 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 13 Aug 2017 23:50:14 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Cc: 27986@debbugs.gnu.org To: Philipp Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 14 01:50:09 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dh2e0-00074i-1k for geb-bug-gnu-emacs@m.gmane.org; Mon, 14 Aug 2017 01:50:08 +0200 Original-Received: from localhost ([::1]:49266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dh2e6-0006dW-GO for geb-bug-gnu-emacs@m.gmane.org; Sun, 13 Aug 2017 19:50:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58655) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dh2dx-0006bZ-Ey for bug-gnu-emacs@gnu.org; Sun, 13 Aug 2017 19:50:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dh2du-0000oI-DC for bug-gnu-emacs@gnu.org; Sun, 13 Aug 2017 19:50:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53016) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dh2du-0000o9-Ad for bug-gnu-emacs@gnu.org; Sun, 13 Aug 2017 19:50:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dh2dt-0003mT-Vr for bug-gnu-emacs@gnu.org; Sun, 13 Aug 2017 19:50:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 Aug 2017 23:50:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27986 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 27986-submit@debbugs.gnu.org id=B27986.150266815114519 (code B ref 27986); Sun, 13 Aug 2017 23:50:01 +0000 Original-Received: (at 27986) by debbugs.gnu.org; 13 Aug 2017 23:49:11 +0000 Original-Received: from localhost ([127.0.0.1]:33461 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dh2d4-0003m7-Of for submit@debbugs.gnu.org; Sun, 13 Aug 2017 19:49:10 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:41500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dh2d2-0003m1-7A for 27986@debbugs.gnu.org; Sun, 13 Aug 2017 19:49:08 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 9D08816086A; Sun, 13 Aug 2017 16:49:02 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id GHhy8tIB_Hzg; Sun, 13 Aug 2017 16:49:00 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2C1D316086B; Sun, 13 Aug 2017 16:49:00 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id R-B35y2tzxLI; Sun, 13 Aug 2017 16:49:00 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.153.184.153]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 073B2160734; Sun, 13 Aug 2017 16:49:00 -0700 (PDT) In-Reply-To: <61980dde-3d68-7200-e7f4-98f62e410060@cs.ucla.edu> Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:135736 Archived-At: This is a multi-part message in MIME format. --------------B763E56ED065112B24927F91 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Getting back to Philipp's original bug report, Apple documentation says m= acOS=20 has a facility like the Linux renameat2 system call (i.e., it's like 'ren= ameat'=20 except it can be told to fail if the destination already exists). Attache= d is a=20 proposed patch to use this facility, which means that the case-insensitiv= ity=20 test would no longer need to be done in macOS. If there's some way to imp= lement=20 renameat_noreplace on MS-Windows we could get rid of the case-insensitivi= ty test=20 there too. I don't have easy access to macOS so I have not installed this patch. It'= d be=20 nice, Philipp, if you could try it out. This patch is independent of the destination-directory patch that I recen= tly=20 proposed in: https://bugs.gnu.org/27986#14 --------------B763E56ED065112B24927F91 Content-Type: text/x-patch; name="0001-Improve-rename-file-behavior-on-macOS.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Improve-rename-file-behavior-on-macOS.patch" =46rom 62605066c4d5a7b91c7800fcc300dbe5082426dc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 13 Aug 2017 16:31:08 -0700 Subject: [PATCH] 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 WINDOWSNT. * src/sysdep.c (renameat_noreplace): Use renameatx_np on macOS, since this provides the necessary atomicity guarantees. --- src/fileio.c | 2 ++ src/sysdep.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/fileio.c b/src/fileio.c index 69079c6ae4..ee70dc6e69 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 =3D false; +#ifdef WINDOWSNT if (!NILP (Ffile_name_case_insensitive_p (file))) { newname =3D Fexpand_file_name (newname, Qnil); case_only_rename =3D !NILP (Fstring_equal (Fdowncase (file), Fdowncase (newname))); } +#endif =20 if (!case_only_rename) newname =3D expand_cp_target (Fdirectory_file_name (file), newname);= diff --git a/src/sysdep.c b/src/sysdep.c index 9eb733221e..4e98f1db24 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -2693,6 +2693,8 @@ 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_NOREPLAC= E); +#elif defined RENAME_EXCL + return renameatx_np (srcfd, src, dstfd, dst, RENAME_EXCL); #else errno =3D ENOSYS; return -1; --=20 2.13.4 --------------B763E56ED065112B24927F91--