From: ·················@gmail.com
Subject: PATHNAME-MATCH-P question
Date: 
Message-ID: <1187245463.525374.248280@x40g2000prg.googlegroups.com>
Hello,

I'm writing a simple function to copy a directory tree to another
directory, it looks like this:

(defun copy-directory (src-dir dst-dir &key overwrite ignore-
pathnames)
  "Copy direcgtory SRC-DIR to directory DST-DIR.  DST-DIR will get
created if it does not exist.  IGNORE-PATHNAMES is a list of pathnames
to ignore."
  (assert (cl-fad:directory-exists-p src-dir))
  (dolist (file (cl-fad:list-directory src-dir))
    (when (loop for ignore-pathname in ignore-pathnames
               never  (pathname-match-p file ignore-pathname))
      (cond ((cl-fad:directory-pathname-p file)
             (copy-directory file (merge-pathnames (make-
pathname :directory (append '(:relative)
 
(last (pathname-directory file))))
                                                   dst-dir)))
            (t
             (let ((dst-file (merge-pathnames (make-pathname :name
(pathname-name file)
                                                             :type
(pathname-type file))
                                              dst-dir)))
               (ensure-directories-exist dst-file)
               (cl-fad:copy-file file dst-file :overwrite
overwrite)))))))

The function is supposed ignore pathnames listed in the IGNORE-
PATHNAMES parameter.  I'm matching these pathnames with PATHNAME-MATCH-
P, which does not work as I expected:

Files work:

CL-USER> (pathname-match-p #P"~/test.txt" #P"test.txt")
T

Matching directories does not work as I expected:

CL-USER> (pathname-match-p #P"~/test/" #P"test/")
NIL
CL-USER> (pathname-match-p #P"~/test/" #P"*/test/")
NIL
CL-USER> (pathname-match-p #P"~/test/" #P"*/test/*")
NIL

Now I'm sure there is a reason for this behavior.  The hyperspec did
not give me any clues.

I'm running Lispworks 5.0.2.   Clisp has the same behavior.

Any help would be greatly appreciated!

AnthonyF

From: Pascal Bourguignon
Subject: Re: PATHNAME-MATCH-P question
Date: 
Message-ID: <87tzr02d4k.fsf@thalassa.informatimago.com>
·················@gmail.com writes:
> Matching directories does not work as I expected:
>
> CL-USER> (pathname-match-p #P"~/test/" #P"test/")
> NIL
> CL-USER> (pathname-match-p #P"~/test/" #P"*/test/")
> NIL
> CL-USER> (pathname-match-p #P"~/test/" #P"*/test/*")
> NIL
>
> Now I'm sure there is a reason for this behavior.  The hyperspec did
> not give me any clues.
>
> I'm running Lispworks 5.0.2.   Clisp has the same behavior.
>
> Any help would be greatly appreciated!

(pathname-match-p #P"~/test/" #P"/**/test/") --> T

#P"~/test/" is higly implementation dependant.



If you want to deal with POSIX paths, then use strings and your own
code.

If you want to deal with portable CL pathname, then I'd stay with
logical pathnames, and avoid physical pathnames, since they're mostly
implementation dependant... (and keeping in mind that the mapping of
logical pathnames to physical pathnames is also totally implementation
dependant).

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

NOTE: The most fundamental particles in this product are held
together by a "gluing" force about which little is currently known
and whose adhesive power can therefore not be permanently
guaranteed.
From: ·················@gmail.com
Subject: Re: PATHNAME-MATCH-P question
Date: 
Message-ID: <1187248132.181421.37340@q4g2000prc.googlegroups.com>
On Aug 15, 11:43 pm, Pascal Bourguignon <····@informatimago.com>
wrote:
>
> (pathname-match-p #P"~/test/" #P"/**/test/") --> T
>
> #P"~/test/" is higly implementation dependant.
>
> If you want to deal with POSIX paths, then use strings and your own
> code.
>
> If you want to deal with portable CL pathname, then I'd stay with
> logical pathnames, and avoid physical pathnames, since they're mostly
> implementation dependant... (and keeping in mind that the mapping of
> logical pathnames to physical pathnames is also totally implementation
> dependant).
>

This helps a lot, thanks!

Anthony