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: Tue, 17 Jan 2012 07:06:47 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> Andreas Schwab <address@hidden> writes:
>
>> You also need to check whether the target is a subdirectory of the
>> source.
> Indeed yes, is there already a function to check this?
> If not what about something like this:

BTW this work also for equality between two directories.
(both GNU/Linux and Windows)

#+BEGIN_SRC lisp
(defun file-subdir-of-p (file1 file2)
  "Check if FILE1 is a subdirectory of FILE2."
  (when (and (not (or (file-remote-p file1)
                      (file-remote-p file2)))
             (not (string= file1 "/"))
             (file-directory-p file1)
             (file-directory-p file2))
    (or (string= file2 "/")
        (loop with f1 = (expand-file-name file1)
              with f2 = (expand-file-name file2)
              with ls1 = (split-string f1 "/" t)
              with ls2 = (split-string f2 "/" t)
              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
              ;; Use here `file-equal-p' when ready to work.
              (string= (file-truename (directory-file-name root))
                       (file-truename(directory-file-name f2)))))))

#+END_SRC



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