1.0.36.28: real LOAD-LOGICAL-PATHNAME-TRANSLATIONS
authorNikodemus Siivola <nikodemus@random-state.net>
Wed, 17 Mar 2010 14:28:00 +0000 (14:28 +0000)
committerNikodemus Siivola <nikodemus@random-state.net>
Wed, 17 Mar 2010 14:28:00 +0000 (14:28 +0000)
 * Read translations from SYS:SITE;HOST.TRANSLATIONS.NEWEST.

 Patch by Michael Weber on sbcl-devel.

NEWS
src/code/target-pathname.lisp
tests/pathnames.impure.lisp
version.lisp-expr

diff --git a/NEWS b/NEWS
index c91a356..2d32718 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ changes relative to sbcl-1.0.36:
     stack frame thrown from.
   * enhancement: WITH-COMPILATION-UNIT :POLICY allows restricting changes to
     compiler optimization qualities inside dynamic extent of its body.
+  * enhancement: LOAD-LOGICAL-PATHNAME-TRANSLATIONS can be used to load
+    translations from SYS:SITE;<HOST>.TRANSLATIONS.NEWEST (thanks to Michael
+    Weber)
   * optimization: SLOT-VALUE and (SETF SLOT-VALUE) take advantage of
     constraint propgation, allowing better compilation eg. when used to
     access structures with WITH-SLOTS. (lp#520366)
index 54a3116..762f472 100644 (file)
@@ -1256,7 +1256,7 @@ system's syntax for files."
 (defun translate-pathname (source from-wildname to-wildname &key)
   #!+sb-doc
   "Use the source pathname to translate the from-wildname's wild and
-   unspecified elements into a completed to-pathname based on the to-wildname."
+unspecified elements into a completed to-pathname based on the to-wildname."
   (declare (type pathname-designator source from-wildname to-wildname))
   (with-pathname (source source)
     (with-pathname (from from-wildname)
@@ -1708,17 +1708,33 @@ system's syntax for files."
 
 (defun load-logical-pathname-translations (host)
   #!+sb-doc
+  "Reads logical pathname translations from SYS:SITE;HOST.TRANSLATIONS.NEWEST,
+with HOST replaced by the supplied parameter. Returns T on success.
+
+If HOST is already defined as logical pathname host, no file is loaded and NIL
+is returned.
+
+The file should contain a single form, suitable for use with
+\(SETF LOGICAL-PATHNAME-TRANSLATIONS).
+
+Note: behaviour of this function is higly implementation dependent, and
+historically it used to be a no-op in SBcL -- the current approach is somewhat
+experimental and subject to change."
   (declare (type string host)
            (values (member t nil)))
   (if (find-logical-host host nil)
       ;; This host is already defined, all is well and good.
       nil
       ;; ANSI: "The specific nature of the search is
-      ;; implementation-defined." SBCL: doesn't search at all
-      ;;
-      ;; FIXME: now that we have a SYS host that the system uses, it
-      ;; might be cute to search in "SYS:TRANSLATIONS;<name>.LISP"
-      (error "logical host ~S not found" host)))
+      ;; implementation-defined."
+      (prog1 t
+        (setf (logical-pathname-translations host)
+              (with-open-file (lpt (make-pathname :host "SYS"
+                                                  :directory '(:absolute "SITE")
+                                                  :name host
+                                                  :type "TRANSLATIONS"
+                                                  :version :newest))
+                (read lpt))))))
 
 (defun !pathname-cold-init ()
   (let* ((sys *default-pathname-defaults*)
index 7ed7250..e2c200e 100644 (file)
   (assert (equal (make-pathname :directory '(:absolute))
                  (read-from-string "#p\"\\\\\\\\\""))))
 
+(with-test (:name :load-logical-pathname-translations)
+  (let* ((cwd (truename "."))
+         (foo (merge-pathnames "llpnt-foo.translations" cwd))
+         (bar (merge-pathnames "llpnt-bar.translations" cwd))
+         (translations (logical-pathname-translations "SYS")))
+    (unwind-protect
+         (progn
+           (with-open-file (f foo :direction :output)
+             (prin1 (list (list "*.TEXT" (make-pathname
+                                          :directory '(:absolute "my" "foo")
+                                          :name :wild :type "txt")))
+                    f))
+           (with-open-file (f bar :direction :output)
+             (prin1 (list (list "*.CL" (make-pathname
+                                        :directory '(:absolute "my" "bar")
+                                        :name :wild :type "lisp"))) f))
+           (setf (logical-pathname-translations "SYS")
+                 (list* (list "SITE;LLPNT-FOO.TRANSLATIONS.NEWEST" foo)
+                        (list "SITE;LLPNT-BAR.TRANSLATIONS.NEWEST" bar)
+                        translations))
+           (assert (load-logical-pathname-translations "LLPNT-FOO"))
+           (assert (load-logical-pathname-translations "LLPNT-BAR"))
+           (assert
+            (and
+             (equal "/my/bar/quux.lisp"
+                    (namestring (translate-logical-pathname "LLPNT-BAR:QUUX.CL")))
+             (equal "/my/foo/quux.txt"
+                    (namestring (translate-logical-pathname "LLPNT-FOO:QUUX.TEXT"))))))
+      (ignore-errors (delete-file foo))
+      (ignore-errors (delete-file bar))
+      (setf (logical-pathname-translations "SYS") translations))))
+
 ;;;; success
index 314304d..89a04bf 100644 (file)
@@ -17,4 +17,4 @@
 ;;; checkins which aren't released. (And occasionally for internal
 ;;; versions, especially for internal versions off the main CVS
 ;;; branch, it gets hairier, e.g. "0.pre7.14.flaky4.13".)
-"1.0.36.27"
+"1.0.36.28"