Raymond Toy pushed to branch master
at cmucl / cmucl
Commits:
-
521f8392
by Raymond Toy
at 2015-12-31T15:38:08Z
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.
-
c7e71ee2
by Raymond Toy
at 2016-01-03T18:11:53Z
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
2 changed files:
Changes:
src/code/pathname.lisp
--- a/src/code/pathname.lisp
+++ b/src/code/pathname.lisp
@@ -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)
- (macrolet ((frob (field &optional (op 'components-match ))
- `(or (null (,field wildname))
- (,op (,field pathname) (,field wildname)))))
- (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))))))
+ (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)))))
+ (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))
+ (return-from pathname-match-p pathname))))))))
;;; SUBSTITUTE-INTO -- Internal
tests/pathname.lisp
--- /dev/null
+++ b/tests/pathname.lisp
@@ -0,0 +1,43 @@
+;; 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:*"))