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?'.
This commit is contained in:
Ludovic Courtès 2018-11-13 09:46:40 +01:00
parent 155956449a
commit 1afe1985f5
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5
2 changed files with 13 additions and 6 deletions

View file

@ -22,8 +22,12 @@ (define-module (guix nar)
#:use-module (guix build syscalls) #:use-module (guix build syscalls)
#:use-module ((guix build utils) #:use-module ((guix build utils)
#:select (delete-file-recursively with-directory-excursion)) #: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)
#:use-module (guix store database) #:use-module (guix store database)
#:use-module (guix ui) ; for '_' #:use-module (guix ui) ; for '_'
#:use-module (gcrypt hash) #:use-module (gcrypt hash)
#:use-module (guix pki) #:use-module (guix pki)
@ -88,15 +92,12 @@ (define* (finalize-store-file source target
REFERENCES and DERIVER. When LOCK? is true, acquire exclusive locks on TARGET REFERENCES and DERIVER. When LOCK? is true, acquire exclusive locks on TARGET
before attempting to register it; otherwise, assume TARGET's locks are already before attempting to register it; otherwise, assume TARGET's locks are already
held." held."
(with-database %default-database-file db
;; XXX: Currently we have to call out to the daemon to check whether TARGET (unless (path-id db target)
;; is valid.
(with-store store
(unless (valid-path? store target)
(when lock? (when lock?
(lock-store-file target)) (lock-store-file target))
(unless (valid-path? store target) (unless (path-id db target)
;; If FILE already exists, delete it (it's invalid anyway.) ;; If FILE already exists, delete it (it's invalid anyway.)
(when (file-exists? target) (when (file-exists? target)
(delete-file-recursively target)) (delete-file-recursively target))

View file

@ -36,7 +36,9 @@ (define-module (guix store database)
#:use-module (ice-9 match) #:use-module (ice-9 match)
#:use-module (system foreign) #:use-module (system foreign)
#:export (sql-schema #:export (sql-schema
%default-database-file
with-database with-database
path-id
sqlite-register sqlite-register
register-path register-path
register-items register-items
@ -85,6 +87,10 @@ (define (call-with-database file proc)
(lambda () (lambda ()
(sqlite-close db))))) (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 ...) (define-syntax-rule (with-database file db exp ...)
"Open DB from FILE and close it when the dynamic extent of EXP... is left. "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." If FILE doesn't exist, create it and initialize it as a new database."