]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix bug in copy-directory copying into an existing directory.
authorChong Yidong <cyd@stupidchicken.com>
Sat, 29 Jan 2011 22:10:51 +0000 (17:10 -0500)
committerChong Yidong <cyd@stupidchicken.com>
Sat, 29 Jan 2011 22:10:51 +0000 (17:10 -0500)
http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01007.html

* files.el (copy-directory): If destination is an existing
directory, copy into a subdirectory there.

lisp/ChangeLog
lisp/files.el

index ee4eae0e41bb4b2dcd940c3862a334a4dc02b747..286f1eeae656ca47bc1792aa812c6f0e6f199f92 100644 (file)
@@ -1,3 +1,8 @@
+2011-01-29  Chong Yidong  <cyd@stupidchicken.com>
+
+       * files.el (copy-directory): If destination is an existing
+       directory, copy into a subdirectory there.
+
 2011-01-29  Andreas Schwab  <schwab@linux-m68k.org>
 
        * emacs-lisp/shadow.el (load-path-shadows-find): Ignore leim-list
index ee77975e38b5d9a333d07c0110897fa6e9e6950f..46597426191dae587586936018b034dc3343d237 100644 (file)
@@ -4756,7 +4756,22 @@ this happens by default."
       ;; 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)) (make-directory newname parents))
+
+      (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].
+       (setq newname (expand-file-name
+                      (file-name-nondirectory
+                       (directory-file-name directory))
+                      newname))
+       (if (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.
       (mapc