diff options
author | Ludovic Courtès <ludo@gnu.org> | 2023-05-21 23:16:34 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2023-05-21 23:16:34 +0200 |
commit | 5fc794ac94dbafdbeeeba739e5e15a0c4bb849b3 (patch) | |
tree | e5eca4d5655efa4302ec4ac6fb9d77597e6db335 | |
parent | 96c871a63d36189717b3355dbb1b7b33355f4234 (diff) |
squash! Create database when it doesn't already exist.origin/wip-guix-index
-rw-r--r-- | guix/scripts/index.scm | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/guix/scripts/index.scm b/guix/scripts/index.scm index 9ba2cccc87..6a6316534a 100644 --- a/guix/scripts/index.scm +++ b/guix/scripts/index.scm @@ -455,7 +455,9 @@ user or system." (if (and system (> (stat:mtime system) (stat:mtime user))) system-database-file user-database-file) - system-database-file))))) + (if system + system-database-file + user-database-file)))))) (define (show-help) (display (G_ "Usage: guix index [OPTIONS...] [search FILE...] @@ -581,14 +583,20 @@ See --database for customization.\n")) (database ((assoc-ref args 'database) (eq? action 'index))) (method (assoc-ref args 'method))) + (define (populate-database database) + (mkdir-p (dirname database)) + ;; Migrate/initialize db to schema at version application-version + (migrate-schema-to-version database) + ;; Finally index packages + (if (eq? method 'manifests) + (index-packages-from-manifests-with-db database) + (index-packages-from-store-with-db database))) + (match action ('search (unless (file-exists? database) - (report-error (G_ "file database '~a' does not exist~%") - database) - (display-hint (G_ "Run @command{guix index} to create it. This -will browse available packages on your system, which may take time.")) - (exit 1)) + (info (G_ "indexing files from ~a...~%") (%store-prefix)) + (populate-database database)) (let* ((file (assoc-ref args 'argument)) (matches (matching-packages-with-db database file))) (print-matching-results matches) @@ -596,10 +604,4 @@ will browse available packages on your system, which may take time.")) (leave (G_ "file '~a' not be found in indexed packages~%") file)))) ('index - (mkdir-p (dirname database)) - ;; Migrate/initialize db to schema at version application-version - (migrate-schema-to-version database) - ;; Finally index packages - (if (eq? method 'manifests) - (index-packages-from-manifests-with-db database) - (index-packages-from-store-with-db database))))))) + (populate-database database)))))) |