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, 10 Sep 2017 23:07:34 -0700 Organization: UCLA Computer Science Department Message-ID: <2ff8e814-b75d-1c9f-a096-8ad644c01ccc@cs.ucla.edu> References: <61980dde-3d68-7200-e7f4-98f62e410060@cs.ucla.edu> <1002ee73-0ab5-409b-831f-0c283c322264@cs.ucla.edu> <83o9rignt6.fsf@gnu.org> <83d17whl72.fsf@gnu.org> <8e6de468-600c-4f2d-a21a-c2ff3a63d065@cs.ucla.edu> <83zib0g221.fsf@gnu.org> <2bb4b7ee-6bf9-df3d-5cd8-ae7992b9f2e7@cs.ucla.edu> <83wp64fdc4.fsf@gnu.org> <83valnfv9u.fsf@gnu.org> <7f0c12f6-57eb-63b9-c296-e062cbf0710c@cs.ucla.edu> <83o9rffqfp.fsf@gnu.org> <83efsbfmij.fsf@gnu.org> <83efs8dp4b.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------56432C9621D5BF0AA3AE3BCD" X-Trace: blaine.gmane.org 1505110122 5023 195.159.176.226 (11 Sep 2017 06:08:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 11 Sep 2017 06:08:42 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 Cc: p.stephani2@gmail.com, johnw@gnu.org, Michael Albinus , rms@gnu.org, 27986-done@debbugs.gnu.org To: Eli Zaretskii , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Sep 11 08:08:36 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 1drHt9-0008BD-8W for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Sep 2017 08:08:07 +0200 Original-Received: from localhost ([::1]:55593 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drHtG-0006Dp-H0 for geb-bug-gnu-emacs@m.gmane.org; Mon, 11 Sep 2017 02:08:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47782) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1drHt8-00069x-IH for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 02:08:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1drHt4-00037Z-F9 for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 02:08:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:51595) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1drHt4-00037R-AR for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 02:08:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1drHt4-0007XB-4e for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2017 02:08:02 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Sep 2017 06:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 27986 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: security Mail-Followup-To: 27986@debbugs.gnu.org, eggert@cs.ucla.edu, p.stephani2@gmail.com Original-Received: via spool by 27986-done@debbugs.gnu.org id=D27986.150511006528934 (code D ref 27986); Mon, 11 Sep 2017 06:08:01 +0000 Original-Received: (at 27986-done) by debbugs.gnu.org; 11 Sep 2017 06:07:45 +0000 Original-Received: from localhost ([127.0.0.1]:60273 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drHsm-0007Wc-Tm for submit@debbugs.gnu.org; Mon, 11 Sep 2017 02:07:45 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:40738) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drHsl-0007WO-7v for 27986-done@debbugs.gnu.org; Mon, 11 Sep 2017 02:07:44 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 99092160CE4; Sun, 10 Sep 2017 23:07:36 -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 pyFXqmPrwibU; Sun, 10 Sep 2017 23:07:35 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 0B49A160CE5; Sun, 10 Sep 2017 23:07:35 -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 o8YSVk5s6tOg; Sun, 10 Sep 2017 23:07:34 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.153.184.153]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id BF2A2160A7A; Sun, 10 Sep 2017 23:07:34 -0700 (PDT) In-Reply-To: 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:136765 Archived-At: This is a multi-part message in MIME format. --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Paul Eggert wrote: > I reviewed all calls to the affected functions and have a few followup = patches=20 > that I plan to install separately soon, and mention here as I do. I installed the patches (attached). Closing the bug report. I'll CC: this to Michael, as the last patch is to the Tramp tests, and he= may=20 want Tramp to become consistent with the new behavior for rename-file etc= . --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/x-patch; name="0001-Make-copy-directory-act-like-copy-file-etc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Make-copy-directory-act-like-copy-file-etc.patch" =46rom e22794867d878d53675fcc91d2ef1ad2494a2ff2 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Sep 2017 22:07:30 -0700 Subject: [PATCH 1/6] Make copy-directory act like copy-file etc. Do the special dance with the destination only if it is a directory name, for consistency with copy-file etc. (Bug#27986). * doc/emacs/files.texi (Copying and Naming): * doc/lispref/files.texi (Create/Delete Dirs): * etc/NEWS: Document this. * lisp/files.el (copy-directory): Treat NEWNAME as special only if it is a directory name. --- doc/emacs/files.texi | 8 ++++---- doc/lispref/files.texi | 5 +++-- etc/NEWS | 4 ++-- lisp/files.el | 22 ++++++++++------------ 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index 0cf46b6..ca4f223 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -1572,10 +1572,10 @@ Copying and Naming =20 @findex copy-directory @kbd{M-x copy-directory} copies directories, similar to the -@command{cp -r} shell command. If @var{new} is an existing directory, -it creates a copy of the @var{old} directory and puts it in @var{new}. -If @var{new} is not an existing directory, it copies all the contents -of @var{old} into a new directory named @var{new}. +@command{cp -r} shell command. If @var{new} is a directory name, it +creates a copy of the @var{old} directory and puts it in @var{new}. +Otherwise it copies all the contents of @var{old} into a new directory +named @var{new}. =20 @cindex renaming files @findex rename-file diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi index eacaf04..901382f 100644 --- a/doc/lispref/files.texi +++ b/doc/lispref/files.texi @@ -2976,8 +2976,9 @@ Create/Delete Dirs =20 @deffn Command copy-directory dirname newname &optional keep-time parent= s copy-contents This command copies the directory named @var{dirname} to -@var{newname}. If @var{newname} names an existing directory, +@var{newname}. If @var{newname} is a directory name, @var{dirname} will be copied to a subdirectory there. +@xref{Directory Names}. =20 It always sets the file modes of the copied files to match the corresponding original file. @@ -2992,7 +2993,7 @@ Create/Delete Dirs =20 The fifth argument @var{copy-contents}, if non-@code{nil}, means to copy the contents of @var{dirname} directly into @var{newname} if the -latter is an existing directory, instead of copying @var{dirname} into +latter is a directory name, instead of copying @var{dirname} into it as a subdirectory. @end deffn =20 diff --git a/etc/NEWS b/etc/NEWS index 4187dd8..136d458 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1285,8 +1285,8 @@ documentation and had inherent races that led to se= curity holes. A call like (rename-file C D) that used the old, undocumented behavior can be written as (rename-file C (file-name-as-directory D)), a formulation portable to both older and newer versions of Emacs. -Affected functions include add-name-to-file, copy-file, -make-symbolic-link, and rename-file. +Affected functions include add-name-to-file, copy-directory, +copy-file, make-symbolic-link, and rename-file. =20 =0C * Lisp Changes in Emacs 26.1 diff --git a/lisp/files.el b/lisp/files.el index 85e649f..7ab6f76 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5501,10 +5501,10 @@ copy-directory create parent directories if they don't exist. Interactively, this happens by default. =20 -If NEWNAME names an existing directory, copy DIRECTORY as a -subdirectory there. However, if called from Lisp with a non-nil -optional argument COPY-CONTENTS, copy the contents of DIRECTORY -directly into NEWNAME instead." +If NEWNAME is a directory name, copy DIRECTORY as a subdirectory +there. However, if called from Lisp with a non-nil optional +argument COPY-CONTENTS, copy the contents of DIRECTORY directly +into NEWNAME instead." (interactive (let ((dir (read-directory-name "Copy directory: " default-directory default-directory t nil))) @@ -5526,19 +5526,17 @@ copy-directory =20 ;; Compute target name. (setq directory (directory-file-name (expand-file-name directory))= - newname (directory-file-name (expand-file-name newname))) + newname (expand-file-name newname)) =20 - (cond ((not (file-directory-p newname)) - ;; If NEWNAME is not an existing directory, create it; + (cond ((not (directory-name-p newname)) + ;; If NEWNAME is not a directory name, create it; ;; that is where we will copy the files of DIRECTORY. (make-directory newname parents)) - ;; If NEWNAME is an existing directory and COPY-CONTENTS + ;; If NEWNAME is a directory name and COPY-CONTENTS ;; is nil, copy into NEWNAME/[DIRECTORY-BASENAME]. ((not copy-contents) - (setq newname (concat - (file-name-as-directory newname) - (file-name-nondirectory - (directory-file-name directory)))) + (setq newname (concat newname + (file-name-nondirectory directory))) (and (file-exists-p newname) (not (file-directory-p newname)) (error "Cannot overwrite non-directory %s with a directory" --=20 2.7.4 --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/x-patch; name="0002-Make-write-file-act-like-copy-file-etc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0002-Make-write-file-act-like-copy-file-etc.patch" =46rom 61946d991b663c9d35a50b758d0108c3cbf8027b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Sep 2017 22:19:01 -0700 Subject: [PATCH 2/6] Make write-file act like copy-file etc. Change write-file to be consistent with the new behavior of copy-file, etc. * etc/NEWS: Mention this. * lisp/files.el (write-file): Treat the destination as special only if it is a directory name. --- etc/NEWS | 3 ++- lisp/files.el | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 136d458..4da4c37 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1286,7 +1286,8 @@ call like (rename-file C D) that used the old, undo= cumented behavior can be written as (rename-file C (file-name-as-directory D)), a formulation portable to both older and newer versions of Emacs. Affected functions include add-name-to-file, copy-directory, -copy-file, make-symbolic-link, and rename-file. +copy-file, format-write-file, make-symbolic-link, rename-file, and +write-file. =20 =0C * Lisp Changes in Emacs 26.1 diff --git a/lisp/files.el b/lisp/files.el index 7ab6f76..611a4c5 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -4212,10 +4212,10 @@ write-file (not current-prefix-arg))) (or (null filename) (string-equal filename "") (progn - ;; If arg is just a directory, + ;; If arg is a directory name, ;; use the default file name, but in that directory. - (if (file-directory-p filename) - (setq filename (concat (file-name-as-directory filename) + (if (directory-name-p filename) + (setq filename (concat filename (file-name-nondirectory (or buffer-file-name (buffer-name)))))) (and confirm --=20 2.7.4 --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/x-patch; name="0003-Make-gnus-copy-file-act-like-copy-file-etc.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0003-Make-gnus-copy-file-act-like-copy-file-etc.patch" =46rom 739593d68742f45e4e35dfc99573c47a5031b646 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Sep 2017 22:21:20 -0700 Subject: [PATCH 3/6] Make gnus-copy-file act like copy-file etc. * etc/NEWS: Mention this. * lisp/gnus/gnus-util.el (gnus-copy-file): Treat the destination as special only if it is a directory name. --- etc/NEWS | 4 ++-- lisp/gnus/gnus-util.el | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 4da4c37..fc40a3a 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1286,8 +1286,8 @@ call like (rename-file C D) that used the old, undo= cumented behavior can be written as (rename-file C (file-name-as-directory D)), a formulation portable to both older and newer versions of Emacs. Affected functions include add-name-to-file, copy-directory, -copy-file, format-write-file, make-symbolic-link, rename-file, and -write-file. +copy-file, format-write-file, gnus-copy-file, make-symbolic-link, +rename-file, and write-file. =20 =0C * Lisp Changes in Emacs 26.1 diff --git a/lisp/gnus/gnus-util.el b/lisp/gnus/gnus-util.el index b509d8a..93541f0 100644 --- a/lisp/gnus/gnus-util.el +++ b/lisp/gnus/gnus-util.el @@ -594,9 +594,6 @@ gnus-copy-file (read-file-name "Copy file to: " default-directory))) (unless to (setq to (read-file-name "Copy file to: " default-directory))) - (when (file-directory-p to) - (setq to (concat (file-name-as-directory to) - (file-name-nondirectory file)))) (copy-file file to)) =20 (defvar gnus-work-buffer " *gnus work*") --=20 2.7.4 --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/x-patch; name="0004-Adjust-ob-tangle-to-new-copy-file-behavior.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0004-Adjust-ob-tangle-to-new-copy-file-behavior.patch" =46rom 74b8615fcceba7b92c4938e1bcc92015f10ae899 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Sep 2017 22:22:55 -0700 Subject: [PATCH 4/6] Adjust ob-tangle to new copy-file behavior * lisp/org/ob-tangle.el (org-babel-tangle-publish): Port to new copy-file behavior. --- lisp/org/ob-tangle.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lisp/org/ob-tangle.el b/lisp/org/ob-tangle.el index 3b05332..2dc55ca 100644 --- a/lisp/org/ob-tangle.el +++ b/lisp/org/ob-tangle.el @@ -197,6 +197,7 @@ org-babel-tangle-publish "Tangle FILENAME and place the results in PUB-DIR." (unless (file-exists-p pub-dir) (make-directory pub-dir t)) + (setq pub-dir (file-name-as-directory pub-dir)) (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file fi= lename))) =20 ;;;###autoload --=20 2.7.4 --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/x-patch; name="0005-Adjust-thumbs-to-new-rename-file-behavior.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0005-Adjust-thumbs-to-new-rename-file-behavior.patch" =46rom 2aa028825920207cca2bacb581111ab780e5d9ee Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Sep 2017 22:28:08 -0700 Subject: [PATCH 5/6] Adjust thumbs to new rename-file behavior * etc/NEWS: Mention this. * lisp/thumbs.el (thumbs-rename-images): Treat the destination as special only if it is a directory name. When there is a marked list, turn the destination into a directory name if it is not already. --- etc/NEWS | 2 +- lisp/thumbs.el | 15 ++++----------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index fc40a3a..3f1df23 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -1287,7 +1287,7 @@ can be written as (rename-file C (file-name-as-dire= ctory D)), a formulation portable to both older and newer versions of Emacs. Affected functions include add-name-to-file, copy-directory, copy-file, format-write-file, gnus-copy-file, make-symbolic-link, -rename-file, and write-file. +rename-file, thumbs-rename-images, and write-file. =20 =0C * Lisp Changes in Emacs 26.1 diff --git a/lisp/thumbs.el b/lisp/thumbs.el index 0665429..d0b5e22 100644 --- a/lisp/thumbs.el +++ b/lisp/thumbs.el @@ -523,23 +523,16 @@ thumbs-rename-images (interactive "FRename to file or directory: ") (let ((files (or thumbs-marked-list (list (thumbs-current-image)))) failures) - (if (and (not (file-directory-p newfile)) - thumbs-marked-list) - (if (file-exists-p newfile) - (error "Renaming marked files to file name `%s'" newfile) - (make-directory newfile t))) + (when thumbs-marked-list + (make-directory newfile t) + (setq newfile (file-name-as-directory newfile))) (if (yes-or-no-p (format "Really rename %d files? " (length files)))= (let ((thumbs-file-list (thumbs-file-alist)) (inhibit-read-only t)) (dolist (file files) (let (failure) (condition-case () - (if (file-directory-p newfile) - (rename-file file - (expand-file-name - (file-name-nondirectory file) - newfile)) - (rename-file file newfile)) + (rename-file file newfile) (file-error (setq failure t) (push file failures))) (unless failure --=20 2.7.4 --------------56432C9621D5BF0AA3AE3BCD Content-Type: text/x-patch; name="0006-Port-tramp-tests-to-new-copy-directory-behavior.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename*0="0006-Port-tramp-tests-to-new-copy-directory-behavior.patch" =46rom 29963648dd11d53088f753e4f9b0491a7b981c0f Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 10 Sep 2017 23:04:10 -0700 Subject: [PATCH 6/6] Port tramp-tests to new copy-directory behavior * test/lisp/net/tramp-tests.el (tramp-test15-copy-directory): Use directory name as arg for copy-directory when we want the special behavior. --- test/lisp/net/tramp-tests.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el index 735211c..4139d50 100644 --- a/test/lisp/net/tramp-tests.el +++ b/test/lisp/net/tramp-tests.el @@ -2117,7 +2117,7 @@ tramp--test-backtrace (should (file-directory-p tmp-name2)) (should (file-exists-p tmp-name5)) ;; Target directory does exist already. - (copy-directory tmp-name1 tmp-name2) + (copy-directory tmp-name1 (file-name-as-directory tmp-name2)) (should (file-directory-p tmp-name3)) (should (file-exists-p tmp-name6))) =20 @@ -2140,7 +2140,8 @@ tramp--test-backtrace ;; Target directory does exist already. (delete-file tmp-name5) (should-not (file-exists-p tmp-name5)) - (copy-directory tmp-name1 tmp-name2 nil 'parents 'contents) + (copy-directory tmp-name1 (file-name-as-directory tmp-name2) + nil 'parents 'contents) (should (file-directory-p tmp-name2)) (should (file-exists-p tmp-name5)) (should-not (file-directory-p tmp-name3)) --=20 2.7.4 --------------56432C9621D5BF0AA3AE3BCD--