;; copy-directory handler.
(let ((handler (or (find-file-name-handler directory 'copy-directory)
(find-file-name-handler newname 'copy-directory)))
- (follow parents))
+ follow)
(if handler
(funcall handler 'copy-directory directory
newname keep-time parents copy-contents)
t)
(make-symbolic-link target newname t)))
;; Else proceed to copy as a regular directory
- (cond ((not (directory-name-p newname))
+ ;; first by creating the destination directory if needed,
+ ;; preparing to follow any symlink to a directory we did not create.
+ (setq follow
+ (if (not (directory-name-p newname))
;; If NEWNAME is not a directory name, create it;
;; that is where we will copy the files of DIRECTORY.
- (make-directory newname parents))
+ (make-directory newname parents)
;; NEWNAME is a directory name. If COPY-CONTENTS is non-nil,
;; create NEWNAME if it is not already a directory;
;; otherwise, create NEWNAME/[DIRECTORY-BASENAME].
- ((if copy-contents
- (or parents (not (file-directory-p newname)))
+ (unless copy-contents
(setq newname (concat newname
(file-name-nondirectory directory))))
- (make-directory (directory-file-name newname) parents))
- (t (setq follow t)))
+ (condition-case err
+ (make-directory (directory-file-name newname) parents)
+ (error
+ (or (file-directory-p newname)
+ (signal (car err) (cdr err)))))))
;; Copy recursively.
(dolist (file
(dest (concat dirname "dest/new/directory/"))
(file (concat (file-name-as-directory source) "file"))
(source2 (concat dirname "source2"))
- (dest2 (concat dirname "dest/new2")))
+ (dest2 (concat dirname "dest/new2"))
+ (source3 (concat dirname "source3/d"))
+ (dest3 (concat dirname "dest3/d")))
(make-directory source)
(write-region "" nil file)
(copy-directory source dest t t t)
(make-directory (concat (file-name-as-directory source2) "a") t)
(copy-directory source2 dest2)
(should (file-directory-p (concat (file-name-as-directory dest2) "a")))
+ (make-directory source3 t)
+ (write-region "x\n" nil (concat (file-name-as-directory source3) "file"))
+ (make-directory dest3 t)
+ (write-region "y\n" nil (concat (file-name-as-directory dest3) "file"))
+ (copy-directory source3 (file-name-directory dest3) t)
(delete-directory dir 'recursive))))
(ert-deftest files-tests-abbreviate-file-name-homedir ()