all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Thierry Volpiatto <thierry.volpiatto@gmail.com>
To: Chong Yidong <cyd@stupidchicken.com>
Cc: Michael Albinus <michael.albinus@gmx.de>, emacs-devel@gnu.org
Subject: Re: bug in copy-directory
Date: Sat, 12 Feb 2011 08:26:11 +0100	[thread overview]
Message-ID: <87vd0pr9ws.fsf@gmail.com> (raw)
In-Reply-To: <87tyga86p0.fsf@stupidchicken.com> (Chong Yidong's message of "Fri, 11 Feb 2011 18:58:19 -0500")

[-- Attachment #1: Type: text/plain, Size: 1100 bytes --]

Chong Yidong <cyd@stupidchicken.com> writes:

> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>
>> Michael Albinus <michael.albinus@gmx.de> writes:
>>
>>>> (defun copy-directory (directory newname &optional keep-time
>>> parents copy-contents-only)
>>>
>>> I'm in favor of this proposal (compared with the recently introduced
>>> `copy-as-subdir'). Thierry's proposal keeps the semantics of
>>> `copy-directory', and the changed semantics are activated by the
>>> optional argument.
>>
>> So when everybody is ok, i can send patch with this modification.
>> Tell me also if copy-contents-only as arg name is ok for you (if you
>> have better idea i take).
>
> This is OK for the trunk.  If we go this route, I'd prefer to revert the
> branch to the Emacs 23.2 behavior, since it requires non-local changes
> and is backward incompatible; then we'll make the change for Emacs 24.
>
> Go ahead and send the patch anytime it's ready.
Sorry, last patch apply on my precedent patch, this one should be correct.

-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 

[-- Attachment #2: dired-create-files --]
[-- Type: application/octet-stream, Size: 7603 bytes --]

Bugfix copy-directory,dired-create-files

From: Thierry Volpiatto <thierry.volpiatto@gmail.com>

lisp/files.el (copy-directory): new arg copy-only-contents Allow to copy contents of directory whitout subdir.

lisp/dired-aux.el (dired-create-files): Don't create subdirectory in dired-copy-file.
---
 lisp/dired-aux.el |    5 +++
 lisp/files.el     |  100 ++++++++++++++++++++++++-----------------------------
 2 files changed, 51 insertions(+), 54 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 28b285f..7c991b7 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1345,6 +1345,7 @@ Special value `always' suppresses confirmation."
 	(when cons (setcar cons cur-dir))))))
 \f
 ;; The basic function for half a dozen variations on cp/mv/ln/ln -s.
+\f
 (defun dired-create-files (file-creator operation fn-list name-constructor
 					&optional marker-char)
 
@@ -1403,6 +1404,8 @@ ESC or `q' to not overwrite any of the remaining files,
                   (cond  ((integerp marker-char) marker-char)
                          (marker-char (dired-file-marker from)) ; slow
                          (t nil))))
+            (when (and (file-directory-p from) (eq file-creator 'dired-copy-file))
+              (setq to (file-name-directory to)))
             (condition-case err
                 (progn
                   (funcall file-creator from to dired-overwrite-confirmed)
@@ -1445,7 +1448,9 @@ ESC or `q' to not overwrite any of the remaining files,
       (message "%s: %s file%s"
 	       operation success-count (dired-plural-s success-count)))))
   (dired-move-to-filename))
+
 \f
+
 (defun dired-do-create-files (op-symbol file-creator operation arg
 					&optional marker-char op1
 					how-to)
diff --git a/lisp/files.el b/lisp/files.el
index 7ac88f8..61131dc 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -4723,23 +4723,21 @@ If RECURSIVE is non-nil, all files in DIRECTORY are deleted as well."
 		 directory 'full directory-files-no-dot-files-regexp)))
       (delete-directory-internal directory)))))
 
-(defun copy-directory (directory newname &optional keep-time
-				 parents copy-as-subdir)
+(defun copy-directory (directory newname &optional keep-time parents contents-only)
   "Copy DIRECTORY to NEWNAME.  Both args must be strings.
+If NEWNAME names an existing directory, copy DIRECTORY as subdirectory there.
+
 This function always sets the file modes of the output files to match
 the corresponding input file.
 
 The third arg KEEP-TIME non-nil means give the output files the same
 last-modified time as the old ones.  (This works on only some systems.)
-A prefix arg makes KEEP-TIME non-nil.
 
-Optional arg PARENTS says whether to create parent directories if
-they don't exist.  When called interactively, PARENTS is t.
+A prefix arg makes KEEP-TIME non-nil.
 
-When NEWNAME is an existing directory, copy DIRECTORY into a
-subdirectory of NEWNAME if optional arg COPY-AS-SUBDIR is
-non-nil, otherwise copy the contents of DIRECTORY into NEWNAME.
-When called interactively, copy into a subdirectory by default."
+Noninteractively, the last argument PARENTS says whether to
+create parent directories if they don't exist.  Interactively,
+this happens by default."
   (interactive
    (let ((dir (read-directory-name
 	       "Copy directory: " default-directory default-directory t nil)))
@@ -4747,7 +4745,7 @@ When called interactively, copy into a subdirectory by default."
 	   (read-file-name
 	    (format "Copy directory %s to: " dir)
 	    default-directory default-directory nil nil)
-	   current-prefix-arg t t)))
+	   current-prefix-arg t)))
   ;; If default-directory is a remote directory, make sure we find its
   ;; copy-directory handler.
   (let ((handler (or (find-file-name-handler directory 'copy-directory)
@@ -4755,50 +4753,44 @@ When called interactively, copy into a subdirectory by default."
     (if handler
 	(funcall handler 'copy-directory directory newname keep-time parents)
 
-      ;; Compute target name.
-      (setq directory (directory-file-name (expand-file-name directory))
-	    newname   (directory-file-name (expand-file-name newname)))
-
-      (unless (file-directory-p directory)
-	(error "%s is not a directory" directory))
-
-      (cond
-       ((not (file-directory-p newname))
-	;; If NEWNAME is not an existing directory, create it;
-	;; that is where we will copy the files of DIRECTORY.
-	(make-directory newname parents))
-       (copy-as-subdir
-	;; If NEWNAME is an existing directory, and we are copying as
-	;; a subdirectory, the target is NEWNAME/[DIRECTORY-BASENAME].
-	(setq newname (expand-file-name
-		       (file-name-nondirectory
-			(directory-file-name directory))
-		       newname))
-	(and (file-exists-p newname)
-	     (not (file-directory-p newname))
-	     (error "Cannot overwrite non-directory %s with a directory"
-		    newname))
-	(make-directory newname t)))
-
-      ;; Copy recursively.
-      (dolist (file
-	       ;; We do not want to copy "." and "..".
-	       (directory-files directory 'full
-				directory-files-no-dot-files-regexp))
-	(let ((target (expand-file-name
-		       (file-name-nondirectory file) newname))
-	      (attrs (file-attributes file)))
-	  (cond ((file-directory-p file)
-		 (copy-directory file target keep-time parents nil))
-		((stringp (car attrs)) ; Symbolic link
-		 (make-symbolic-link (car attrs) target t))
-		(t
-		 (copy-file file target t keep-time)))))
-
-      ;; Set directory attributes.
-      (set-file-modes newname (file-modes directory))
-      (if keep-time
-	  (set-file-times newname (nth 5 (file-attributes directory)))))))
+        ;; Compute target name.
+        (setq directory (directory-file-name (expand-file-name directory))
+              newname   (directory-file-name (expand-file-name newname)))
+
+        (if (not (file-directory-p newname))
+            ;; If NEWNAME is not an existing directory, create it; that
+            ;; is where we will copy the files of DIRECTORY.
+            (make-directory newname parents)
+            ;; If NEWNAME is an existing directory, we will copy into
+            ;; NEWNAME/[DIRECTORY-BASENAME].
+            (unless contents-only
+              (setq newname (expand-file-name
+                             (file-name-nondirectory
+                              (directory-file-name directory))
+                             newname))
+              (and (file-exists-p newname)
+                   (not (file-directory-p newname))
+                   (error "Cannot overwrite non-directory %s with a directory"
+                          newname))
+              (make-directory newname t)))
+
+        ;; Copy recursively.
+        (dolist (file
+                  ;; We do not want to copy "." and "..".
+                  (directory-files directory 'full
+                                   directory-files-no-dot-files-regexp))
+          (if (file-directory-p file)
+              (copy-directory file newname keep-time parents)
+              (let ((target (expand-file-name (file-name-nondirectory file) newname))
+                    (attrs (file-attributes file)))
+                (if (stringp (car attrs)) ; Symbolic link
+                    (make-symbolic-link (car attrs) target t)
+                    (copy-file file target t keep-time)))))
+
+        ;; Set directory attributes.
+        (set-file-modes newname (file-modes directory))
+        (when keep-time
+          (set-file-times newname (nth 5 (file-attributes directory)))))))
 \f
 (put 'revert-buffer-function 'permanent-local t)
 (defvar revert-buffer-function nil

  parent reply	other threads:[~2011-02-12  7:26 UTC|newest]

Thread overview: 92+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-27 15:18 bug in copy-directory Thierry Volpiatto
2011-01-28  1:13 ` Chong Yidong
2011-01-28  9:05   ` Thierry Volpiatto
2011-01-28 15:02   ` Stefan Monnier
2011-01-28 16:30     ` Chong Yidong
2011-01-28 16:51       ` Lennart Borgman
2011-01-28 17:05         ` Andreas Schwab
2011-01-28 17:08           ` Lennart Borgman
2011-01-28 17:18             ` Andreas Schwab
2011-01-28 17:13         ` Thierry Volpiatto
2011-01-28 17:17           ` Lennart Borgman
2011-01-28 18:11             ` Thierry Volpiatto
2011-01-28 18:28               ` Lennart Borgman
2011-01-28 20:12                 ` Jan Djärv
2011-01-28 20:48                   ` Lennart Borgman
2011-01-28 22:44                     ` Jan Djärv
2011-01-28 22:55                       ` Lennart Borgman
2011-01-28 18:31             ` Eli Zaretskii
2011-01-28 18:33               ` Thierry Volpiatto
2011-01-28 18:35       ` Stefan Monnier
2011-01-29 22:12         ` Chong Yidong
2011-01-29 22:51           ` Thierry Volpiatto
2011-01-30 10:51             ` Michael Albinus
2011-01-30 13:54               ` Thierry Volpiatto
2011-01-30 14:05                 ` Michael Albinus
2011-01-30 10:46           ` Michael Albinus
2011-01-30 13:51             ` Thierry Volpiatto
2011-01-30 14:12               ` Michael Albinus
2011-01-30 14:36                 ` Thierry Volpiatto
2011-01-30 15:21                   ` Thierry Volpiatto
2011-01-30 16:00                     ` Thierry Volpiatto
2011-01-30 17:43                     ` Michael Albinus
2011-01-30 18:07                       ` Thierry Volpiatto
2011-01-30 18:32                         ` Thierry Volpiatto
2011-01-30 18:36                         ` Michael Albinus
2011-01-30 19:07                           ` Thierry Volpiatto
2011-01-30 21:18                             ` Thierry Volpiatto
2011-01-31 17:06             ` Chong Yidong
2011-02-01  9:44               ` Michael Albinus
2011-02-01 11:57                 ` Thierry Volpiatto
2011-02-02  8:19                 ` Thierry Volpiatto
2011-02-02  9:24                 ` Thierry Volpiatto
2011-02-02  9:47                   ` Michael Albinus
2011-02-02 20:48                     ` Thierry Volpiatto
2011-02-04  8:40                       ` Thierry Volpiatto
2011-02-04 10:17                         ` Michael Albinus
2011-02-04 17:28                           ` Thierry Volpiatto
2011-02-04 19:20                             ` Michael Albinus
2011-02-04 20:00                               ` Thierry Volpiatto
2011-02-06  5:01                                 ` Chong Yidong
2011-02-06  6:23                                   ` Thierry Volpiatto
2011-02-06 12:03                                   ` Michael Albinus
2011-02-06 13:33                                     ` Chong Yidong
2011-02-07 16:43                                       ` Michael Albinus
2011-02-07 17:32                                         ` Thierry Volpiatto
2011-02-08  9:18                                           ` Michael Albinus
2011-02-08 10:58                                             ` Thierry Volpiatto
2011-02-08 11:29                                               ` Michael Albinus
2011-02-08 15:06                                                 ` Thierry Volpiatto
2011-02-08 15:22                                                   ` Michael Albinus
2011-02-08 16:39                                                   ` Michael Albinus
2011-02-09  0:46                                         ` Chong Yidong
2011-02-09  7:13                                           ` Thierry Volpiatto
2011-02-09  8:32                                             ` Michael Albinus
2011-02-09 15:37                                               ` Chong Yidong
2011-02-09 16:07                                                 ` Michael Albinus
2011-02-09 16:11                                                 ` Thierry Volpiatto
2011-02-09 16:50                                                   ` Chong Yidong
2011-02-09 17:37                                                     ` Thierry Volpiatto
2011-02-06 17:22                                     ` Thierry Volpiatto
2011-02-06 17:46                                       ` Thierry Volpiatto
2011-02-07 15:22                                         ` Stefan Monnier
2011-02-07 16:02                                           ` Thierry Volpiatto
2011-02-07 18:55                                             ` Stefan Monnier
2011-02-07 20:00                                               ` Thierry Volpiatto
2011-02-08  3:32                                                 ` Stefan Monnier
2011-02-09 16:02                                           ` Chong Yidong
2011-02-09 21:42                                             ` Stefan Monnier
2011-02-11  8:12                                               ` Thierry Volpiatto
2011-02-11  8:32                                                 ` Michael Albinus
2011-02-11  9:48                                                   ` Thierry Volpiatto
2011-02-11 10:36                                                     ` Michael Albinus
2011-02-11 23:58                                                     ` Chong Yidong
2011-02-12  7:06                                                       ` Thierry Volpiatto
2011-02-12  9:01                                                         ` Michael Albinus
2011-02-12 18:42                                                           ` Chong Yidong
2011-02-12 19:41                                                         ` Chong Yidong
2011-02-12 21:55                                                           ` Thierry Volpiatto
2011-02-12 22:46                                                             ` Chong Yidong
2011-02-14 11:40                                                               ` Thierry Volpiatto
2011-02-12  7:26                                                       ` Thierry Volpiatto [this message]
2011-02-06 17:47                                       ` Michael Albinus

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=87vd0pr9ws.fsf@gmail.com \
    --to=thierry.volpiatto@gmail.com \
    --cc=cyd@stupidchicken.com \
    --cc=emacs-devel@gnu.org \
    --cc=michael.albinus@gmx.de \
    /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.