Subject: Re: bug#5343: 23.1.91; recursive directory copying is broken

From: Stephen Berman <[email-masked]>
Date: Sat, 09 Jan 2010 22:53:58 +0100

On Sat, 09 Jan 2010 00:14:58 +0100 Stephen Berman <[email-masked]> wrote:

> 1. emacs -Q
> 2. Make a directory /tmp/test, add to it a file named "a" and a
>    directory named "test", and add to /tmp/test/test a file named "b".
> 3. Type `M-x copy-directory RET /tmp/test RET ~ RET' to copy /tmp/test
>    recursively to ~.
> 4. Type `C-x d' and at the prompt `~' to visit ~ in Dired, put the
>    cursor on the directory "test" and type `i' to open "test" as a
>    subdirectory.  This is the result:
>
>   /home/steve/test:
>   total used in directory 16 available 7794948
>   -rw-r--r--  1 steve users    4 2010-01-08 23:57 a
>   -rw-r--r--  1 steve users    7 2010-01-08 23:57 b

This is due to the following code in copy-directory:

    (if (and (file-directory-p newname)
             (not (string-equal (file-name-nondirectory directory)
    				(file-name-nondirectory newname))))
	(setq newname
	      (expand-file-name (file-name-nondirectory directory) newname)))

Specifically, the equality check prevents newname from being changed
from "home/steve/test" to "home/steve/test/test".  Removing this check,
as in the below patch, fixes the above breakage.  I don't see any real
problem this check prevents, but maybe I'm overlooking something.

Steve Berman

2010-01-09  Stephen Berman  <[email-masked]>

	* files.el (copy-directory): Don't check equality of source and
	target nondirectory names (bug#5343).

*** /tmp/ediff7644I7H	2010-01-09 22:23:07.000000000 +0100
--- /home/steve/bzr/emacs/quickfixes/lisp/files.el	2010-01-09 21:41:52.000000000 +0100
***************
*** 4714,4722 ****
        ;; Compute target name.
        (setq directory (directory-file-name (expand-file-name directory))
  	    newname   (directory-file-name (expand-file-name newname)))
!       (if (and (file-directory-p newname)
! 	       (not (string-equal (file-name-nondirectory directory)
! 				  (file-name-nondirectory newname))))
  	  (setq newname
  		(expand-file-name (file-name-nondirectory directory) newname)))
        (if (not (file-directory-p newname)) (make-directory newname parents))
--- 4714,4720 ----
        ;; Compute target name.
        (setq directory (directory-file-name (expand-file-name directory))
  	    newname   (directory-file-name (expand-file-name newname)))
!       (if (file-directory-p newname)
  	  (setq newname
  		(expand-file-name (file-name-nondirectory directory) newname)))
        (if (not (file-directory-p newname)) (make-directory newname parents))