Commit 4110028efab816a731807133942a63200c67402d

Thomas de Grivel 2015-07-23T18:44:47

Improve OpenBSD probes.

diff --git a/unix/defs.lisp b/unix/defs.lisp
index f9f81a6..d567424 100644
--- a/unix/defs.lisp
+++ b/unix/defs.lisp
@@ -53,10 +53,10 @@
 (eval-when (:compile-toplevel :load-toplevel :execute)
 
   (defvar *cksum-legacy-algorithms*
-    '(:cksum :sum :sysvsum))
+    '(:cksum))
 
   (defvar *cksum-algorithms*
-    `(:md4 :md5 :rmd160 :sha1 :sha224 :sha256 :sha384 :sha512
+    `(:md5 :rmd160 :sha1 :sha224 :sha256 :sha384 :sha512
            ,@*cksum-legacy-algorithms*)))
 
 (defvar *probe-file-content-size-limit* 8192)
diff --git a/unix/openbsd.lisp b/unix/openbsd.lisp
index a44cbe1..c045ea1 100644
--- a/unix/openbsd.lisp
+++ b/unix/openbsd.lisp
@@ -22,33 +22,40 @@
 
 (define-resource-class openbsd-pkg (pkg)
   ()
-  ((probe-openbsd-pkg :properties (:name :version :flavors))))
+  ((probe-openbsd-pkg :properties (:versions))))
 
-(define-syntax pkg_info<1> (name version flavors)
-  #~|\s*((?:[^-\s]+)(?:-[^-0-9\s][^-\s]*)*)-([0-9][^-\s]*)(-[^\s]+)?|
+(define-syntax pkg_info<1> (name version)
+  #~|\s*((?:[^-\s]+)(?:-[^-0-9\s][^-\s]*)*)-([0-9][^-\s]*-[^\s]+)?|
   "Syntax for pkg_info(1) on OpenBSD"
-  (values name version (re-matches #~|[^-]+| flavors)))
+  (values name (list version)))
 
 (defgeneric probe-openbsd-pkg (resource os))
 
 (defmethod probe-openbsd-pkg ((pkg openbsd-pkg) (os os-openbsd))
   (let ((id (resource-id pkg)))
-    (multiple-value-bind #1=(name version flavors)
-      (iter (pkg_info<1> #1# in
+    (multiple-value-bind #1=(versions)
+      (iter (pkg_info<1> (name versions) in
                          (run "pkg_info | egrep ~A" (sh-quote (str "^" id "-"))))
             (when (string= id name)
               (return (values* #1#))))
       (properties* #1#))))
 
+(defmethod merge-property-values ((pkg openbsd-pkg)
+                                  (property (eql :versions))
+                                  (old list)
+                                  (new list))
+  (sort (remove-duplicates (append old new))
+        #'string<))
+
 (defmethod probe-installed-packages% ((host host) (os os-openbsd))
   (with-host host
-    (iter (pkg_info<1> #1=(name version flavors)
+    (iter (pkg_info<1> #1=(name versions flavors)
                        in (run "pkg_info"))
           (for pkg = (resource 'openbsd-pkg name))
           (add-probed-properties pkg (properties* #1#))
-          (collect pkg))))
+          (adjoining pkg))))
 
-(defun probe-installed-packages (&optional (host *host*))
+(defun probe-installed-packages (&optional (host (current-host)))
   (probe-installed-packages% host (host-os host)))
 
 #+nil
@@ -58,7 +65,10 @@
 (describe-probed (resource 'openbsd-pkg "emacs"))
 
 #+nil
-(probe-installed-packages *localhost* (host-os *localhost*))
+(probe-installed-packages)
+
+#+nil
+(map nil #'describe-probed (probe-installed-packages))
 
 #+nil
 (run "pkg_info -q | grep emacs-")