bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarch


From: Michael Albinus
Subject: bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarchy
Date: Fri, 24 Feb 2012 17:21:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> (defun files-equal-p (file1 file2)
>   "Return non-nil if FILE1 and FILE2 name the same file."
>   (let ((handler (or (find-file-name-handler file1 'files-equal-p)
>                      (find-file-name-handler file2 'files-equal-p))))
>     (if handler
>         (funcall handler 'files-equal-p file1 file2)
>       (and (equal (file-remote-p file1) (file-remote-p file2))

Not needed anymore, you have called the handler already.

>            (equal (file-attributes (file-truename file1))
>                   (file-attributes (file-truename file2)))))))

Here we have the discussion about the inode numbers. But this is an edge
case; let's go this way. Eli will fix it for Windows :-)

> (defun file-subdir-of-p (dir1 dir2)
>   "Return non-nil if DIR1 is a subdirectory of DIR2.
> Note that a directory is treated by this function as a subdirectory of itself.
> This function only works when its two arguments already exist,
> when they don't, it returns nil."
>   (let ((handler (or (find-file-name-handler dir1 'file-subdir-of-p)
>                      (find-file-name-handler dir2 'file-subdir-of-p))))
>     (if handler
>         (funcalll handler 'file-subdir-of-p dir1 dir2)
>       (when (and (file-directory-p dir1)
>                  (file-directory-p dir2))
>         (loop with f1 = (file-truename dir1)
>               with f2 = (file-truename dir2)
>               with ls1 = (or (split-string f1 "/" t) (list "/"))
>               with ls2 = (or (split-string f2 "/" t) (list "/"))
>               for p = (string-match "^/" f1)
>               for i in ls1
>               for j in ls2
>               when (string= i j)
>               concat (if p (concat "/" i) (concat i "/"))
>               into root
>               finally return
>               (files-equal-p (file-truename root) f2))))))

Looks OK on the first glance.

> BTW I have added the COPY-CONTENTS arg to your handler in
> `copy-directory'.

Thanks.

Best regards, Michael.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]