From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#28834: 25.1; dired-do-copy: allow to copy into a nonexistent directory Date: Sun, 15 Oct 2017 13:42:48 +0900 Message-ID: <87shel2f93.fsf@gmail.com> References: <006201d344da$d9316a50$8b943ef0$@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1508042666 32630 195.159.176.226 (15 Oct 2017 04:44:26 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 15 Oct 2017 04:44:26 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) To: 28834@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Oct 15 06:44:17 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 1e3amU-0006SZ-WD for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Oct 2017 06:44:07 +0200 Original-Received: from localhost ([::1]:56148 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3amc-0001HG-5r for geb-bug-gnu-emacs@m.gmane.org; Sun, 15 Oct 2017 00:44:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33511) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e3amV-0001Gv-Qr for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2017 00:44:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e3amQ-0001qb-VQ for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2017 00:44:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:60400) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e3amQ-0001qV-RI for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2017 00:44:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1e3amQ-0004Dn-Gf for bug-gnu-emacs@gnu.org; Sun, 15 Oct 2017 00:44:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 15 Oct 2017 04:44:02 +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: Original-Received: via spool by 28834-submit@debbugs.gnu.org id=B28834.150804258316133 (code B ref 28834); Sun, 15 Oct 2017 04:44:02 +0000 Original-Received: (at 28834) by debbugs.gnu.org; 15 Oct 2017 04:43:03 +0000 Original-Received: from localhost ([127.0.0.1]:40845 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3alT-0004C8-6W for submit@debbugs.gnu.org; Sun, 15 Oct 2017 00:43:03 -0400 Original-Received: from mail-pg0-f50.google.com ([74.125.83.50]:50426) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e3alR-0004Bf-PJ for 28834@debbugs.gnu.org; Sun, 15 Oct 2017 00:43:02 -0400 Original-Received: by mail-pg0-f50.google.com with SMTP id y7so4245621pgb.7 for <28834@debbugs.gnu.org>; Sat, 14 Oct 2017 21:43:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-transfer-encoding; bh=zwYpaBJj9ko9WGFvku37/jeVfzQhKt8HrN9EkrqxiKA=; b=oxGBjZGO90/O19NdX7HWHZtTqBHlRQPbEKWG3ozV8RLkshaZSJ2yboAu4ONhQHS5bw QYtGqEgSGnXME/YOc/UOTh/yZTckzMa0Q8W2rewoBNqVKIrSXIOPuKwtYZIzTsakoyGK 41QFL6OnBtYLkS6YhgLhamvRPyBcm53O9iC16uJ0SBamdjikxsONdb9AiAfBFJSfa5s2 KkNwus6cecgGHH64GhWAWK5cGUv/cMcjtW+QbcDOca7lIxBkC6rw7IrXnSH82bdfrghN MWOyXcOYk+Wj5XxaZABbuQ/5Ts7T3wYEDWL/e2pebV+YX79dHC/UCk6TNLge03/ytzRJ HxaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-transfer-encoding; bh=zwYpaBJj9ko9WGFvku37/jeVfzQhKt8HrN9EkrqxiKA=; b=fz0D8e2dW+bhOx0SSr/w7dmVXmHbzkbVv4TDKujmQ9fy5RGHuPcmGQiwYYcffV34Nm QwlkSVtW11Z3RCog8Migpu0Cs6Y+eaOwcOru4OJJSVeZDgYb/1+BX/42nPkyLixeMRM1 1rYD4a32JBKqOfPQPCulZ/Kk2nFRsPc6MG7/eFFbMxrXVn4qaSdtl+o6BElQklnITcow 1wjjZT0qKFWxGv1yxezp6WNrYRhoOQ/5kgCakJ/WkK4ZPP7BX40UCjFcQs9ia1ZZzSTY viAWGMwBwIRlezbM9HwIKMbV2f5+eP42H5eKfXVbPdgW2HrpcsGmJoBmVmD7a4qpS0DV Xw4Q== X-Gm-Message-State: AMCzsaVmSQPJJriA3YPZkDPecoE5InWm0mQCo7JqAefrxdItwSjuavoW OcOpaAURAV73PFCRhOL6w+A= X-Google-Smtp-Source: ABhQp+SsSqbgY8xYg7Xj+RnKT/SHCjZ7bi9CBfCCUup6XcRwu/apOQm9BLaeZKwGVJBdK3D4m93YFw== X-Received: by 10.98.60.198 with SMTP id b67mr8443pfk.163.1508042575721; Sat, 14 Oct 2017 21:42:55 -0700 (PDT) Original-Received: from calancha-pc (203.191.218.133.dy.bbexcite.jp. [133.218.191.203]) by smtp.gmail.com with ESMTPSA id f3sm8963322pfd.82.2017.10.14.21.42.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 14 Oct 2017 21:42:54 -0700 (PDT) In-Reply-To: <006201d344da$d9316a50$8b943ef0$@gmail.com> (alexei's message of "Sat, 14 Oct 2017 13:54:45 +0300") 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:138439 Archived-At: "alexei28" writes: > I want to copy file from "d:/TEMP/test/test.txt" to nonexistent directory= "d:/TEMP/test/new/" with Dired > Copy =E2=80=98d:/TEMP/test/test.txt=E2=80=99 to =E2=80=98d:/TEMP/test/new= /test.txt=E2=80=99 failed: > > (file-error Copying file Operation not permitted d:/TEMP/test/test.txt d:= /TEMP/test/new/test.txt) > > It would be good if Emacs can autocreate not exist directory when copy/mo= ve files. It might has sense that Dired handle the creation of those destination dirs. WDOT? --8<-----------------------------cut here---------------start------------->= 8--- commit 1325ea21a069b5c539157390fb5df2eca76adecb Author: Tino Calancha Date: Sun Oct 15 13:34:08 2017 +0900 Dired: Allow to copy/rename files into a non-existent dir =20=20=20=20 * lisp/dired-aux.el (dired--create-dirs): New defun. (dired-copy-file-recursive, dired-rename-file): Use it (Bug#28834). * doc/emacs/dired.texi (Operating on Files): Update manual. * etc/NEWS (Changes in Specialized Modes and Packages in Emacs 27.1) Announce feature. * lisp/dired-aux-tests.el (dired-test-bug28834): Add test. diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index db5dea329b..48013a3221 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -645,7 +645,8 @@ Operating on Files @item C @var{new} @key{RET} 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}. +name. Dired creates any non-existent directories in @var{new}. This is +like the shell command @code{cp}. =20 @vindex dired-copy-preserve-time If @code{dired-copy-preserve-time} is non-@code{nil}, then copying @@ -674,7 +675,8 @@ Operating on Files @cindex moving files (in Dired) @item R @var{new} @key{RET} Rename the specified files (@code{dired-do-rename}). If you rename a -single file, the argument @var{new} is the new name of the file. If +single file, the argument @var{new} is the new name of the file. Dired +creates any non-existent directories in @var{new}. If you rename several files, the argument @var{new} is the directory into which to move the files (this is like the shell command @command{mv}). =20 diff --git a/etc/NEWS b/etc/NEWS index 716b0309a5..08291fc39f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -56,6 +56,12 @@ whether '"' is also replaced in 'electric-quote-mode'. = If non-nil, * Changes in Specialized Modes and Packages in Emacs 27.1 =20 +** Dired + +--- +*** dired-do-copy and dired-rename-file now create non-existent +directories in the destination. + ** Edebug =20 +++ diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index 7e2252fcf1..fcea8f1b13 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1548,6 +1548,10 @@ dired-copy-file =20 (declare-function make-symbolic-link "fileio.c") =20 +(defun dired--create-dirs (dir) + (unless (file-exists-p dir) + (dired-create-directory dir))) + (defun dired-copy-file-recursive (from to ok-flag &optional preserve-time top recursive) (when (and (eq t (car (file-attributes from))) @@ -1564,6 +1568,7 @@ dired-copy-file-recursive (if (stringp (car attrs)) ;; It is a symlink (make-symbolic-link (car attrs) to ok-flag) + (dired--create-dirs (file-name-directory to)) (copy-file from to ok-flag preserve-time)) (file-date-error (push (dired-make-relative from) @@ -1573,6 +1578,7 @@ dired-copy-file-recursive ;;;###autoload (defun dired-rename-file (file newname ok-if-already-exists) (dired-handle-overwrite newname) + (dired--create-dirs (file-name-directory newname)) (rename-file file newname ok-if-already-exists) ; error is caught in -cr= eate-files ;; Silently rename the visited file of any buffer visiting this file. (and (get-file-buffer file) diff --git a/test/lisp/dired-aux-tests.el b/test/lisp/dired-aux-tests.el index d41feb1592..d8114d8401 100644 --- a/test/lisp/dired-aux-tests.el +++ b/test/lisp/dired-aux-tests.el @@ -40,5 +40,25 @@ (should-not (dired-do-shell-command "ls ? ./`?`" nil files))) (delete-file foo)))) =20 +(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))) + (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))) + ;; clean up + (delete-directory foo 'recursive) + (delete-file from)))) + + (provide 'dired-aux-tests) ;; dired-aux-tests.el ends here --8<-----------------------------cut here---------------end--------------->= 8--- In GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.11) of 2017-10-15 Repository revision: eed3a3d9e95d2c5346a23c9d92ca4e5848330183