[Git][cmucl/cmucl][master] 3 commits: Fix #27: PATHNAME-MATCH-P loops for logical pathnames
Raymond Toy
rtoy at common-lisp.net
Sun Sep 4 20:48:38 UTC 2016
Raymond Toy pushed to branch master at cmucl / cmucl
Commits:
c07cad4b by Raymond Toy at 2016-09-03T19:51:47-07:00
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.
- - - - -
37c549c6 by Raymond Toy at 2016-09-04T13:43:03-07:00
Factor out the common part of pathname-match-p.
- - - - -
efc9519f by Raymond Toy at 2016-09-04T20:48:35+00:00
Merge branch 'rtoy-fix-27-pathname-match-p' into 'master'
Fix #27: pathname-match-p infinite recursion
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.
See merge request !10
- - - - -
2 changed files:
- src/code/pathname.lisp
- tests/pathname.lisp
Changes:
=====================================
src/code/pathname.lisp
=====================================
--- a/src/code/pathname.lisp
+++ b/src/code/pathname.lisp
@@ -1219,6 +1219,32 @@ a host-structure or string."
(:version (frob (%pathname-version pathname)))))))
+(defun %%pathname-match-p (pathname 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))))
+
+;; Like PATHNAME-MATCH-P but the pathnames should not be search-lists.
+;; Primarily intended for TRANSLATE-LOGICAL-PATHNAME and friends,
+;; because PATHNAME-MATCH-P calls TRANSLATE-LOGICAL-PATHNAME, causing
+;; infinite recursion.
+(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)
+ (%%pathname-match-p pathname wildname))))
+
;;; PATHNAME-MATCH-P -- Interface
;;;
(defun pathname-match-p (in-pathname in-wildname)
@@ -1231,17 +1257,8 @@ a host-structure or string."
(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))))))))
+ (when (%%pathname-match-p pathname wildname)
+ (return-from pathname-match-p pathname)))))))
;;; SUBSTITUTE-INTO -- Internal
@@ -1476,7 +1493,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 +2188,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)
=====================================
tests/pathname.lisp
=====================================
--- 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;"))))
+
View it on GitLab: https://gitlab.common-lisp.net/cmucl/cmucl/compare/a8934d1590ee605e2f4f02071a71a8887c2d036a...efc9519f14f92355e671620748188497db120b94
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cmucl-cvs/attachments/20160904/25163e4d/attachment-0001.html>
More information about the cmucl-cvs
mailing list