summary refs log tree commit diff
diff options
context:
space:
mode:
authorPierre Neidhardt <mail@ambrevar.xyz>2020-08-24 12:47:51 +0200
committerPierre Neidhardt <mail@ambrevar.xyz>2020-09-05 09:34:39 +0200
commit25147f983bdf432b03e8271abe0318f4812f94ba (patch)
tree54facc0eca26722648e719522a0215e9a73212d6
parent49b52c2c7be03caf3636632c31f4451d5bc88125 (diff)
downloadguix-25147f983bdf432b03e8271abe0318f4812f94ba.tar.gz
guix: Automatically quote and append wildcard to filesearch patterns.
* guix/scripts/filesearch.scm (search-file-package): Use sqlite-bind-arguments
instead of brittle format.
Quote patterns to avoid interpretation of special characters like "-" in
"transmission-gtk".
Append wildcard to search patterns to be smarteer at inferring the
matches (e.g. "perl" should match "perl5").
-rw-r--r--guix/scripts/filesearch.scm16
1 files changed, 10 insertions, 6 deletions
diff --git a/guix/scripts/filesearch.scm b/guix/scripts/filesearch.scm
index a409dc152e..3cb542d7b7 100644
--- a/guix/scripts/filesearch.scm
+++ b/guix/scripts/filesearch.scm
@@ -138,7 +138,7 @@ matches both \"/bin/foo\" and \"/usr/bin/foo\" but not \"barbin\"."
                          #:files (directory-files path)))))
          output-path-pairs)))
 
-(define (search-file-package pattern)
+(define (search-file-package pattern . more-patterns)
   "Return corresponding packages.
 Packages or ordered by most relevant last.
 Path is subject to SQLite \"full-text search\" pattern matching.
@@ -155,10 +155,14 @@ Example patterns:
         db
         ;; REVIEW: Is this inner join cheap?
         (string-append
-         "select subpath, name, version, output"
-         " from Files inner join Packages on Files.package = Packages.id"
-         (format #f " where Files.subpath match '~a' order by rank" pattern))
-      stmt
+         "SELECT subpath, name, version, output"
+         " FROM Files INNER JOIN Packages ON Files.package = Packages.id"
+         " WHERE Files.subpath MATCH :pattern ORDER BY RANK")
+        stmt
+      (sqlite-bind-arguments stmt #:pattern (string-concatenate
+                                             (map (lambda (s)
+                                                    (format #f "~s*" s))
+                                                  (cons pattern more-patterns))))
       (map vector->list
            (sqlite-fold cons '() stmt)))))
 
@@ -206,7 +210,7 @@ Example patterns:
 ;; with xdelta (probably not since it would send entries for Guix versions
 ;; that the user does not have).
 
-;; Statistics
+;; Measures
 ;;
 ;; Context:
 ;; - 14,000 packages