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, 24 Feb 2012 17:02:16 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (gnu/linux)

Michael Albinus <address@hidden> writes:

> Thierry Volpiatto <address@hidden> writes:
>
>> However, Michael I would like to have more precisions for the call of
>> tramp handlers.
>
> What exactly? It's always the same scenario: Check for the handler, and
> if there is any, call it. You can reuse the code snippet from all
> functions which do so.
>
> If you are uncertain, show your code; I'll comment.
So here the functions, please have a look:

(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))
           (equal (file-attributes (file-truename file1))
                  (file-attributes (file-truename file2)))))))

(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))))))


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

-- 
  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]