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: Thierry Volpiatto
Subject: bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarchy
Date: Fri, 13 Jan 2012 19:59:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> Michael Albinus <address@hidden> writes:
>
>> Juanma Barranquero <address@hidden> writes:
>>
>>> On Fri, Jan 13, 2012 at 15:14, Drew Adams <address@hidden> wrote:
>>>
>>>>  (and (equal (file-remote-p file1) (file-remote-p file2))
>>>
>>> Why is the file-remote-p needed?
>>
>> For some simple cases, `file-remote-p' does the correct expansion.
>>
>> (file-remote-p "/sudo::") => "/sudo:address@hidden:"
>>
>> With this expansion, "/sudo::/path/file" and "/sudo:host:/path/file"
>> would be equal.
>
> What about this?
>
> (defun file-name-equal-p (name1 name2 &optional dir)
>   (let* ((n1     (file-truename (expand-file-name name1 dir)))
>          (n2     (file-truename (expand-file-name name2 dir)))
>          (rhost1 (file-remote-p n1 'host))
>          (rhost2 (file-remote-p n2 'host))
>          (lname1 (file-remote-p n1 'localname))
>          (lname2 (file-remote-p n2 'localname))
>          (rem-n1 (if rhost1
>                      (list (cons rhost1 lname1))
>                      (list (cons (system-name) n1))))
>          (rem-n2 (if rhost2
>                      (list (cons rhost2 lname2))
>                      (list (cons (system-name) n2)))))
>     (loop for (x1 . y1) in rem-n1
>           for (x2 . y2) in rem-n2
>           thereis (and (equal x1 x2)
>                        (equal y1 y2)))))
>
> (file-name-equal-p "/home/thierry/Test" "~/Test")
> ;=>t
> (file-name-equal-p "/home/thierry/Test" "/home/thierry/tmp/Test")
> ;=>nil
> (file-name-equal-p "/ssh:thievol:/home/thierry/Test" 
> "/scpc:thievol:/home/thierry/Test")
> ;=>t
> (file-name-equal-p "/sudo::/home/thierry/Test" "/sudo::~/Test")
> ;=>nil
> (file-name-equal-p "/sudo::/home/thierry/Test" "~/Test")
> ;=>t
> (file-name-equal-p "/home/thierry/tmp" "/tmp")
> ;=>nil

We need also to use file-name-as-directory for this use case:
(file-name-equal-p "/home/thierry/Test" "~/Test/")
;=>t

--8<---------------cut here---------------start------------->8---
(defun file-name-equal-p (name1 name2 &optional dir)
  (let* ((n1     (file-name-as-directory
                  (file-truename (expand-file-name name1 dir))))
         (n2     (file-name-as-directory
                  (file-truename (expand-file-name name2 dir))))
         (rhost1 (file-remote-p n1 'host))
         (rhost2 (file-remote-p n2 'host))
         (lname1 (file-remote-p n1 'localname))
         (lname2 (file-remote-p n2 'localname))
         (rem-n1 (if rhost1
                     (list (cons rhost1 lname1))
                     (list (cons (system-name) n1))))
         (rem-n2 (if rhost2
                     (list (cons rhost2 lname2))
                     (list (cons (system-name) n2)))))
    (loop for (x1 . y1) in rem-n1
          for (x2 . y2) in rem-n2
          thereis (and (equal x1 x2)
                       (equal y1 y2)))))
--8<---------------cut here---------------end--------------->8---

-- 
  Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 






reply via email to

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