diff options
author | Chong Yidong <cyd@stupidchicken.com> | 2011-01-29 17:10:51 -0500 |
---|---|---|
committer | Chong Yidong <cyd@stupidchicken.com> | 2011-01-29 17:10:51 -0500 |
commit | 506bd8110ada0dc0bf3068d157641de793236af7 (patch) | |
tree | 8f4ac2056d94ec6e8cd5d7ad5d46356e2b48664c | |
parent | ff9a468cf786c9653e9175a5482342bb02573c36 (diff) | |
download | emacs-506bd8110ada0dc0bf3068d157641de793236af7.tar.gz |
Fix bug in copy-directory copying into an existing directory.
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.
-rw-r--r-- | lisp/ChangeLog | 5 | ||||
-rw-r--r-- | lisp/files.el | 17 |
2 files changed, 21 insertions, 1 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index f0a37ebaeb9..de8e7b4b82c 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -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 diff --git a/lisp/files.el b/lisp/files.el index ee77975e38b..46597426191 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -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 |