From c07cad4bf7507b1c795fee9670d636070da44f66 Mon Sep 17 00:00:00 2001 From: Raymond Toy <toy.raymond@gmail.com> Date: Sat, 3 Sep 2016 19:51:47 -0700 Subject: [PATCH] Fix #27: PATHNAME-MATCH-P loops for logical pathnames When support for search-lists was added to PATHNAME-MATCH-P, support for logical pathnames was broken because PATHNAME-MATCH-P eventually calls TRANSLATE-LOGICAL-PATHNAME which calls PATHNAME-MATCH-P with logical pathnames. This caused infinite recursion. So add back the original PATHNAME-MATCH-P, but rename to %PATHNAME-MATCH-P and use that in TRANSLATE-LOGICAL-PATHNAME and friends. Add test for this case too. --- src/code/pathname.lisp | 24 ++++++++++++++++++++++-- tests/pathname.lisp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/code/pathname.lisp b/src/code/pathname.lisp index 217bbc919..44ac9019c 100644 --- a/src/code/pathname.lisp +++ b/src/code/pathname.lisp @@ -1219,6 +1219,26 @@ a host-structure or string." (:version (frob (%pathname-version pathname))))))) +;; Like PATHNAME-MATCH-P but the pathnames should not be search-lists. +(defun %pathname-match-p (in-pathname in-wildname) + "Pathname matches the wildname template?" + (declare (type path-designator in-pathname) + ;; 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)))))) + ;;; PATHNAME-MATCH-P -- Interface ;;; (defun pathname-match-p (in-pathname in-wildname) @@ -1476,7 +1496,7 @@ a host-structure or string." (with-pathname (source source) (with-pathname (from from-wildname) (with-pathname (to to-wildname) - (unless (pathname-match-p source from) + (unless (%pathname-match-p source from) (didnt-match-error source from)) (let* ((source-host (%pathname-host source)) (to-host (%pathname-host to)) @@ -2171,7 +2191,7 @@ a host-structure or string." :format-control (intl:gettext "No translation for ~S") :format-arguments (list pathname))) (destructuring-bind (from to) x - (when (pathname-match-p pathname from) + (when (%pathname-match-p pathname from) (return (translate-logical-pathname (translate-pathname pathname from to))))))) (pathname pathname) diff --git a/tests/pathname.lisp b/tests/pathname.lisp index 73b31a1e3..6cff018cb 100644 --- a/tests/pathname.lisp +++ b/tests/pathname.lisp @@ -41,3 +41,35 @@ ;; Tests where both args are search-lists. (assert-true "foo:foo.lisp" "bar:*")) + +;; Verify PATHNAME-MATCH-P works with logical pathnames. (Issue 27) +;; This test modeled after a test from asdf +(defun setup-logical-host () + (let ((root *default-pathname-defaults*) + (bin-type (pathname-type (compile-file-pathname "foo.lisp")))) + (setf (logical-pathname-translations "ASDFTEST") + `((,(format nil "**;*.~a" bin-type) + ,(merge-pathnames (make-pathname :directory '(:relative :wild-inferiors) + :name :wild :type bin-type :version nil))) + (,(format nil "**;*.~a.*" bin-type) + ,(merge-pathnames (make-pathname :directory '(:relative "asdf-bin" :wild-inferiors) + :name :wild :type bin-type + :defaults root))) + ("**;*.*.*" + ,(merge-pathnames (make-pathname :directory '(:relative "asdf-src" :wild-inferiors) + :name :wild :type :wild :version :wild))) + ("**;*.*" + ,(merge-pathnames (make-pathname :directory '(:relative "asdf-src" :wild-inferiors) + :name :wild :type :wild :version nil))) + ("**;*" + ,(merge-pathnames (make-pathname :directory '(:relative "asdf-src" :wild-inferiors) + :name :wild :type nil :version nil))))))) +(setup-logical-host) + +(define-test pathname-match-p.logical-pathname + (assert-true (pathname-match-p + (make-pathname :host "ASDFTEST" + :directory '(:absolute "system2" "module4") + :name nil :type nil) + (parse-namestring "ASDFTEST:system2;module4;")))) + -- GitLab