Commit c7e71ee2 authored by Raymond Toy's avatar Raymond Toy
Browse files

Merge branch 'rtoy-issue-16' into 'master'

Handle search lists in pathname-match-p.

Allow search lists in pathname-match-p.  For each arg, we enumerate
the possible values of the search list and try to find a match between
the path and the wild path.  If there's a match, return true.

Tests added for some cases of pathname-match-p with search lists.

Fix issue #16.

See merge request !6
parents f3b73541 521f8392
Loading
Loading
Loading
Loading
+7 −4
Changes for src/code/pathname.lisp: 7 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -1227,18 +1227,21 @@ a host-structure or string."
	   ;; Not path-designator because a file-stream can't have a
	   ;; wild pathname.
	   (type (or string pathname) in-wildname))
  (with-pathname (pathname in-pathname)
    (with-pathname (wildname in-wildname)
  (with-pathname (in-path in-pathname)
    (enumerate-search-list (pathname in-path)
      (with-pathname (in-wild in-wildname)
	(enumerate-search-list (wildname in-wild)
	  (macrolet ((frob (field &optional (op 'components-match ))
		       `(or (null (,field wildname))
			    (,op (,field pathname) (,field wildname)))))
	(and (or (null (%pathname-host wildname))
	    (when (and (or (null (%pathname-host wildname))
			   (eq (%pathname-host wildname) (%pathname-host pathname)))
		       (frob %pathname-device)
		       (frob %pathname-directory directory-components-match)
		       (frob %pathname-name)
		       (frob %pathname-type)
	     (frob %pathname-version))))))
		       (frob %pathname-version))
	      (return-from pathname-match-p pathname))))))))


;;; SUBSTITUTE-INTO -- Internal

tests/pathname.lisp

0 → 100644
+43 −0
Changes for tests/pathname.lisp: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
;; Tests for pathnames

(defpackage :pathname-tests
  (:use :cl :lisp-unit))

(in-package "PATHNAME-TESTS")

;; Define "foo:" search list.  /tmp and /usr should exist on all unix
;; systems.
(setf (ext:search-list "foo:")
      '(#p"/tmp/" #p"/usr/"))

;; Define "bar:" search list.  The second entry should match the
;; second entry of the "foo:" search list.
(setf (ext:search-list "bar:")
      '(#p"/bin/" #p"/usr/"))

(define-test pathname-match-p.search-lists
    (:tag :search-list)
  ;; Basic tests where the wild path is search-list

  (assert-true (pathname-match-p "/tmp/foo.lisp" "foo:*"))
  (assert-true (pathname-match-p "/tmp/zot/foo.lisp" "foo:**/*"))
  (assert-true (pathname-match-p "/tmp/zot/foo.lisp" "foo:**/*.lisp"))
  ;; These match because the second entry of the "foo:" search list is
  ;; "/usr/".
  (assert-true (pathname-match-p "/usr/foo.lisp" "foo:*"))
  (assert-true (pathname-match-p "/usr/bin/foo" "foo:**/*"))
  (assert-true (pathname-match-p "/usr/bin/foo.lisp" "foo:**/*.lisp"))

  ;; This fails because "/bin/" doesn't match any path of the search
  ;; list.
  (assert-false (pathname-match-p "/bin/foo.lisp" "foo:*"))

  ;; Basic test where the pathname is a search-list and the wild path is not.
  (assert-true (pathname-match-p "foo:foo.lisp" "/tmp/*"))
  (assert-true (pathname-match-p "foo:foo" "/usr/*"))
  (assert-true (pathname-match-p "foo:zot/foo.lisp" "/usr/**/*.lisp"))

  (assert-false (pathname-match-p "foo:foo" "/bin/*"))
  
  ;; Tests where both args are search-lists.
  (assert-true "foo:foo.lisp" "bar:*"))