From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#28834: 25.1; dired-do-copy: allow to copy into a nonexistent directory Date: Mon, 16 Oct 2017 19:12:12 +0300 Message-ID: <83o9p7f4wz.fsf@gnu.org> References: <006201d344da$d9316a50$8b943ef0$@gmail.com> <87shel2f93.fsf@gmail.com> <329916c9-5a00-4460-83db-f16b98e79edb@default> <87mv4r3gat.fsf@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1508170402 26678 195.159.176.226 (16 Oct 2017 16:13:22 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 16 Oct 2017 16:13:22 +0000 (UTC) Cc: 28834@debbugs.gnu.org To: Tino Calancha Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Oct 16 18:13:18 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 1e480n-00053j-Ig for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Oct 2017 18:13:05 +0200 Original-Received: from localhost ([::1]:33938 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e480u-0001kf-Sl for geb-bug-gnu-emacs@m.gmane.org; Mon, 16 Oct 2017 12:13:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57481) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e480o-0001kK-6J for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 12:13:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e480k-0007XT-6j for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 12:13:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35386) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e480k-0007XI-2N for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 12:13:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e480j-00035Q-P6 for bug-gnu-emacs@gnu.org; Mon, 16 Oct 2017 12:13:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 16 Oct 2017 16:13:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 28834 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 28834-submit@debbugs.gnu.org id=B28834.150817036311837 (code B ref 28834); Mon, 16 Oct 2017 16:13:01 +0000 Original-Received: (at 28834) by debbugs.gnu.org; 16 Oct 2017 16:12:43 +0000 Original-Received: from localhost ([127.0.0.1]:44067 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e480R-00034r-1g for submit@debbugs.gnu.org; Mon, 16 Oct 2017 12:12:43 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:38078) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e480O-00034b-7I for 28834@debbugs.gnu.org; Mon, 16 Oct 2017 12:12:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e480F-00074P-3d for 28834@debbugs.gnu.org; Mon, 16 Oct 2017 12:12:35 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:57126) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e480F-00074F-0q; Mon, 16 Oct 2017 12:12:31 -0400 Original-Received: from [176.228.60.248] (port=2003 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1e480E-0005oF-8D; Mon, 16 Oct 2017 12:12:30 -0400 In-reply-to: <87mv4r3gat.fsf@gmail.com> (message from Tino Calancha on Mon, 16 Oct 2017 12:47:06 +0900) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] 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:138534 Archived-At: > From: Tino Calancha > Cc: 28834@debbugs.gnu.org, Eli Zaretskii > Date: Mon, 16 Oct 2017 12:47:06 +0900 > > Thank you for the explanation. Let's discuss the updated patch: Thanks, I have a few comments: > diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi > index db5dea329b..0f37ac60ac 100644 > --- a/doc/emacs/dired.texi > +++ b/doc/emacs/dired.texi > @@ -646,6 +646,16 @@ Operating on Files > Copy the specified files (@code{dired-do-copy}). The argument @var{new} > is the directory to copy into, or (if copying a single file) the new > name. This is like the shell command @code{cp}. > +The option @var{dired-create-destination-dirs} controls whether Dired > +should create non-existent directories in @var{new}. This sentence is redundant (repeated right after it), and also uses @var incorrectly. > +@videnx dired-create-destination-dirs ^^^^^^^ A typo. > +The option @code{dired-create-destination-dirs} controls whether Dired > +should create non-existent directories in the destination while > +copying/renaming files. The default value @code{never} means Dired > +never creates such missing directories; the value @code{always}, > +means Dired automatically creates them; the value @code{prompt} > +means Dired asks you for confirmation before creating them. I think we generally use 'ask', not 'prompt' in these cases. > diff --git a/etc/NEWS b/etc/NEWS > index 716b0309a5..e5cec45426 100644 > --- a/etc/NEWS > +++ b/etc/NEWS > @@ -56,6 +56,13 @@ whether '"' is also replaced in 'electric-quote-mode'. If non-nil, > > * Changes in Specialized Modes and Packages in Emacs 27.1 > > +** Dired > + > +--- Since you've updated the manual, this should be "+++", not "---". > +*** The new user option 'dired-create-destination-dirs' controls whether > +'dired-do-copy' and 'dired-rename-file' must create non-existent ^^^^ "Should", not "must". > +directories in the destination. > + > ** Edebug > > +++ > diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el > index 7e2252fcf1..0e415b7738 100644 > --- a/lisp/dired-aux.el > +++ b/lisp/dired-aux.el > @@ -1548,6 +1548,26 @@ dired-copy-file > > (declare-function make-symbolic-link "fileio.c") > > +(defcustom dired-create-destination-dirs 'never > + "Whether Dired should create destination dirs when copying/removing files. > +If never, don't create them. > +If always, create them without ask. > +If prompt, ask for user confirmation." The symbols should be quoted: `never', `always', etc. Btw, perhaps it's better to use nil instead of 'never'. > +(defun dired--create-dirs (dir) > + (unless (file-exists-p dir) > + (pcase dired-create-destination-dirs > + ('never nil) > + ('always (dired-create-directory dir)) > + ('prompt > + (when (yes-or-no-p (format "Create destination dir '%s'? " dir)) > + (dired-create-directory dir)))))) Is use of pcase really justified here? > +(ert-deftest dired-test-bug28834 () > + "test for https://debbugs.gnu.org/28834 ." > + (let* ((from (make-temp-file "from")) > + (foo (make-temp-file "foo" 'dir)) > + (bar (file-name-as-directory (expand-file-name "bar" foo))) > + (qux (file-name-as-directory (expand-file-name "qux" foo))) > + (tmpdir temporary-file-directory) > + (to-cp (expand-file-name "foo-cp" bar)) > + (to-mv (expand-file-name "foo-mv" qux)) > + (dired-create-destination-dirs 'always)) > + (unwind-protect > + (progn > + (dired-copy-file-recursive from to-cp nil) > + (should (file-exists-p to-cp)) > + (dired-rename-file from to-mv nil) > + (should (file-exists-p to-mv)) > + ;; Repeat the same with `dired-create-destination-dirs' set to 'never. > + (dired-rename-file to-mv from nil) > + (delete-file to-cp) > + (delete-directory bar) > + (delete-directory qux) > + (let ((dired-create-destination-dirs 'never)) > + (should-error (dired-copy-file-recursive from to-cp nil)) > + (should-error (dired-rename-file from to-mv nil)))) This doesn't test the 3rd value. Why is that?