From: Tino Calancha <tino.calancha@gmail.com>
To: 28834@debbugs.gnu.org
Subject: bug#28834: 25.1; dired-do-copy: allow to copy into a nonexistent directory
Date: Sun, 15 Oct 2017 13:42:48 +0900 [thread overview]
Message-ID: <87shel2f93.fsf@gmail.com> (raw)
In-Reply-To: <006201d344da$d9316a50$8b943ef0$@gmail.com> (alexei's message of "Sat, 14 Oct 2017 13:54:45 +0300")
"alexei28" <alexei28@gmail.com> writes:
> I want to copy file from "d:/TEMP/test/test.txt" to nonexistent directory "d:/TEMP/test/new/" with Dired
> Copy ‘d:/TEMP/test/test.txt’ to ‘d:/TEMP/test/new/test.txt’ 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/move 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 <tino.calancha@gmail.com>
Date: Sun Oct 15 13:34:08 2017 +0900
Dired: Allow to copy/rename files into a non-existent dir
* 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}.
@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}).
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,
\f
* Changes in Specialized Modes and Packages in Emacs 27.1
+** Dired
+
+---
+*** dired-do-copy and dired-rename-file now create non-existent
+directories in the destination.
+
** Edebug
+++
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
(declare-function make-symbolic-link "fileio.c")
+(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 -create-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))))
+(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
next prev parent reply other threads:[~2017-10-15 4:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-14 10:54 bug#28834: 25.1; Dired+ not copy file to nonexistent directory alexei28
2017-10-14 15:50 ` Drew Adams
2017-10-15 4:42 ` Tino Calancha [this message]
2017-10-15 14:21 ` bug#28834: 25.1; dired-do-copy: allow to copy into a " Eli Zaretskii
2017-10-15 14:47 ` Tino Calancha
2017-10-15 15:43 ` Drew Adams
2017-10-16 3:47 ` Tino Calancha
2017-10-16 16:12 ` Eli Zaretskii
2017-10-17 4:49 ` Tino Calancha
2017-10-17 16:36 ` Eli Zaretskii
2017-10-21 4:13 ` Tino Calancha
2017-10-17 1:49 ` Drew Adams
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87shel2f93.fsf@gmail.com \
--to=tino.calancha@gmail.com \
--cc=28834@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.