Subject: Re: bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarchy

From: Michael Albinus <[email-masked]>
Date: Fri, 13 Jan 2012 23:51:52 +0100

Stefan Monnier <[email-masked]> writes:

>> What about this?
>> (defun file-name-equal-p (name1 name2 &optional dir)
>>   (let* ((n1     (file-truename (expand-file-name name1 dir)))
>
> There's a crucial line missing between the above two.  It should clearly
> document what this function is expected to do.  E.g. it should make it
> clear if (and if so, to what extent) the function is allowed to refer to
> the actual file system(s) as opposed to only relying on the
> provided strings.

If the file name strings are not obviously equal, `file-truename' will
refer to the underlying file system(s). There will be some checks to
avoid this for remote files, for example due to different host names
used in both file names, but this are implementation details.

This is the difference to `file-remote-p', which works only with the
given file name strings. Something like

(defun file-equal-p (name1 name2 &optional dir)
  "Return non-nil if NAME1 and NAME2 refer to the same file in the file system.
If either name is not absolute, then it is expanded relative to
DIR (if given) or `default-directory' for the test."
  (let ((fn1 (expand-file-name name1 dir))
	(fn2 (expand-file-name name2 dir)))
    (cond
     ((string-equal fn1 fn2))
     ((and (file-remote-p fn1) (file-remote-p fn2))
      (let ((handler (or (find-file-name-handler fn1 'file-equal-p)
			 (find-file-name-handler fn2 'file-equal-p))))
	(if handler (funcall handler 'file-equal-p name1 name2 dir))))
     ((or (file-remote-p fn1) (file-remote-p fn2)) nil)
     (t (if the-var-which-tells-us-case-insensitivity
	    (string-equal (downcase (file-truename fn1))
			  (downcase (file-truename fn1)))
	  (string-equal (file-truename fn1) (file-truename fn1))))))

>         Stefan

Best regards, Michael.