diff mbox series

[bug#66799] Fix guix locate clear database "no files to search for" error and unnesecary database rebuilding

Message ID AM0PR10MB3586C8F3024F8576EE02F0F980A3A@AM0PR10MB3586.EURPRD10.PROD.OUTLOOK.COM
State New
Headers show
Series [bug#66799] Fix guix locate clear database "no files to search for" error and unnesecary database rebuilding | expand

Commit Message

Maciej Kalandyk Oct. 28, 2023, 5:43 p.m. UTC
This patch fixes error with guix locate --clear that causes it to display error when no files are supplied

Change-Id: I0e9ca223d6406c78b0dd8ff93976c3077d89e103
Signed-off-by: Maciej Kalandyk <m.kalandyk@outlook.com>
---
 guix/scripts/locate.scm | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)


base-commit: 6d7e181ba18d11c92409a93936025fb46b9c8171

Comments

Ludovic Courtès Nov. 15, 2023, 5:36 p.m. UTC | #1
Hi Maciej,

Maciej Kalandyk <m.kalandyk@outlook.com> skribis:

> This patch fixes error with guix locate --clear that causes it to display error when no files are supplied
>
> Change-Id: I0e9ca223d6406c78b0dd8ff93976c3077d89e103
> Signed-off-by: Maciej Kalandyk <m.kalandyk@outlook.com>

I fixed it slightly differently in
69d9a020949c77c77b449c1faf04397b95eef5b7 and added a test in
‘tests/guix-locate.sh’ so this bug doesn’t come to haunt us again.

Thank you!

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/locate.scm b/guix/scripts/locate.scm
index ae64f46896..93faa1aea2 100644
--- a/guix/scripts/locate.scm
+++ b/guix/scripts/locate.scm
@@ -634,6 +634,9 @@  (define-command (guix-locate . args)
               (_
                (leave (G_ "~a: unknown indexing method~%") method))))))
 
+      (if (and (null? files) (not (or update? clear?)))
+          (leave (G_ "no files to search for~%")))
+
       ;; Populate the database if needed.
       (let* ((stat   (stat database #f))
              (age    (and stat (file-age stat)))
@@ -649,20 +652,18 @@  (define-command (guix-locate . args)
 
       (if (assoc-ref opts 'stats?)
           (print-statistics database)
-          (match (call-with-database database
-                   (lambda (db)
-                     (append-map (lambda (file)
-                                   (matching-packages db file
-                                                      #:glob? glob?))
-                                 files)))
-            (()
-             (if (null? files)
-                 (unless update?
-                   (leave (G_ "no files to search for~%")))
+          (unless (null? files)
+              (match (call-with-database database
+                       (lambda (db)
+                         (append-map (lambda (file)
+                                       (matching-packages db file
+                                                          #:glob? glob?))
+                                     files)))
+                (()
                  (leave (N_ "file~{ '~a'~} not found in database '~a'~%"
                             "files~{ '~a'~} not found in database '~a'~%"
                             (length files))
-                        files database)))
-            (matches
-             (leave-on-EPIPE
-              (print-matching-results matches))))))))
+                        files database))
+                (matches
+                 (leave-on-EPIPE
+                  (print-matching-results matches)))))))))