guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/06: nar: Access the database instead of connecting to the daemon.


From: Ludovic Courtès
Subject: 01/06: nar: Access the database instead of connecting to the daemon.
Date: Tue, 13 Nov 2018 09:05:22 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit 1afe1985f5bffef76872f4c9e87115b46a4a3d47
Author: Ludovic Courtès <address@hidden>
Date:   Tue Nov 13 09:46:40 2018 +0100

    nar: Access the database instead of connecting to the daemon.
    
    * guix/store/database.scm (%default-database-file): New variable.
    (path-id): Export.
    * guix/nar.scm (finalize-store-file): Use 'with-database' instead of
    'with-store', and use 'path-id' instead of 'valid-path?'.
---
 guix/nar.scm            | 13 +++++++------
 guix/store/database.scm |  6 ++++++
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/guix/nar.scm b/guix/nar.scm
index 0495b4a..8894f10 100644
--- a/guix/nar.scm
+++ b/guix/nar.scm
@@ -22,8 +22,12 @@
   #:use-module (guix build syscalls)
   #:use-module ((guix build utils)
                 #:select (delete-file-recursively with-directory-excursion))
+
+  ;; XXX: Eventually we should use (guix store database) exclusively, and not
+  ;; (guix store) since this is "daemon-side" code.
   #:use-module (guix store)
   #:use-module (guix store database)
+
   #:use-module (guix ui)                          ; for '_'
   #:use-module (gcrypt hash)
   #:use-module (guix pki)
@@ -88,15 +92,12 @@
 REFERENCES and DERIVER.  When LOCK? is true, acquire exclusive locks on TARGET
 before attempting to register it; otherwise, assume TARGET's locks are already
 held."
-
-  ;; XXX: Currently we have to call out to the daemon to check whether TARGET
-  ;; is valid.
-  (with-store store
-    (unless (valid-path? store target)
+  (with-database %default-database-file db
+    (unless (path-id db target)
       (when lock?
         (lock-store-file target))
 
-      (unless (valid-path? store target)
+      (unless (path-id db target)
         ;; If FILE already exists, delete it (it's invalid anyway.)
         (when (file-exists? target)
           (delete-file-recursively target))
diff --git a/guix/store/database.scm b/guix/store/database.scm
index 341276b..3879691 100644
--- a/guix/store/database.scm
+++ b/guix/store/database.scm
@@ -36,7 +36,9 @@
   #:use-module (ice-9 match)
   #:use-module (system foreign)
   #:export (sql-schema
+            %default-database-file
             with-database
+            path-id
             sqlite-register
             register-path
             register-items
@@ -85,6 +87,10 @@ create it and initialize it as a new database."
                   (lambda ()
                     (sqlite-close db)))))
 
+(define %default-database-file
+  ;; Default location of the store database.
+  (string-append %store-database-directory "/db.sqlite"))
+
 (define-syntax-rule (with-database file db exp ...)
   "Open DB from FILE and close it when the dynamic extent of EXP... is left.
 If FILE doesn't exist, create it and initialize it as a new database."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]