[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
08/09: guix: register-path: return #t on success.
From: |
Caleb Ristvedt |
Subject: |
08/09: guix: register-path: return #t on success. |
Date: |
Mon, 12 Jun 2017 03:05:06 -0400 (EDT) |
reepca pushed a commit to branch guile-daemon
in repository guix.
commit b418ff86b7ebc80feee79c824866f99a11ce5315
Author: Caleb Ristvedt <address@hidden>
Date: Thu Jun 8 02:56:37 2017 -0500
guix: register-path: return #t on success.
* guix/store.scm: (register-path): return #t on success.
---
guix/store.scm | 96 ++++++++++++++++++++++++++++++----------------------------
1 file changed, 50 insertions(+), 46 deletions(-)
diff --git a/guix/store.scm b/guix/store.scm
index 6284736..53a855c 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -1280,9 +1280,9 @@ future duplicates can hardlink to it."
(link path links-path))))
;; TODO: Handle databases not existing yet (what should the default behavior
-;; be? Figuring out how the C++ stuff currently does it sounds like a lot of
-;; grepping for global variables...). Also, return #t on success like the
-;; documentation says we should.
+;; be? The C++ version checks for a number in the file "schema" in the
+;; database directory and compares it to a constant, and uses that to decide
+;; whether to "upgrade" or initialize the database).
(define* (register-path path
#:key (references '()) deriver prefix state-directory)
@@ -1300,49 +1300,53 @@ Return #t on success.
Use with care as it directly modifies the store! This is primarily meant to
be used internally by the daemon's build hook."
- (let* ((db-dir (cond
- (state-directory
- (string-append state-directory "/db"))
- (prefix
- ;; If prefix is specified, the value of NIX_STATE_DIR
- ;; (which affects %state-directory) isn't supposed to
- ;; affect db-dir, only the compile-time-customized
- ;; default should.
- (string-append prefix %localstatedir "/guix/db"))
- (else
- %store-database-directory)))
- (store-dir (if prefix
- ;; same situation as above
- (string-append prefix %storedir)
- %store-directory))
- (to-register (if prefix
- (string-append %storedir "/" (basename path))
- ;; note: we assume here that if path is, for
- ;; example, /foo/bar/gnu/store/thing.txt and prefix
- ;; isn't given, then an environment variable has
- ;; been used to change the store directory to
- ;; /foo/bar/gnu/store, since otherwise real-path
- ;; would end up being /gnu/store/thing.txt, which is
- ;; probably not the right file in this case.
- path))
- (real-path (string-append store-dir "/" (basename path))))
- (let-values (((hash nar-size)
- (nar-sha256 real-path)))
- (sqlite-register
- #:dbpath (string-append db-dir "/db.sqlite")
- #:path to-register
- #:references references
- #:deriver deriver
- #:hash (string-append "sha256:"
- (bytevector->base16-string hash))
- #:nar-size nar-size)
- ;; reset-timestamps prints a message on each invocation that we probably
- ;; don't want.
- (with-output-to-port
- (%make-void-port "w")
- (lambda ()
- (reset-timestamps real-path)))
- (deduplicate real-path store-dir hash))))
+ (false-if-exception
+ (let* ((db-dir (cond
+ (state-directory
+ (string-append state-directory "/db"))
+ (prefix
+ ;; If prefix is specified, the value of NIX_STATE_DIR
+ ;; (which affects %state-directory) isn't supposed to
+ ;; affect db-dir, only the compile-time-customized
+ ;; default should.
+ (string-append prefix %localstatedir "/guix/db"))
+ (else
+ %store-database-directory)))
+ (store-dir (if prefix
+ ;; same situation as above
+ (string-append prefix %storedir)
+ %store-directory))
+ (to-register (if prefix
+ (string-append %storedir "/" (basename path))
+ ;; note: we assume here that if path is, for
+ ;; example, /foo/bar/gnu/store/thing.txt and prefix
+ ;; isn't given, then an environment variable has
+ ;; been used to change the store directory to
+ ;; /foo/bar/gnu/store, since otherwise real-path
+ ;; would end up being /gnu/store/thing.txt, which is
+ ;; probably not the right file in this case.
+ path))
+ (real-path (string-append store-dir "/" (basename path))))
+ (let-values (((hash nar-size)
+ (nar-sha256 real-path)))
+ (sqlite-register
+ #:dbpath (string-append db-dir "/db.sqlite")
+ #:path to-register
+ #:references references
+ #:deriver deriver
+ #:hash (string-append "sha256:"
+ (bytevector->base16-string hash))
+ #:nar-size nar-size)
+ ;; reset-timestamps prints a message on each invocation that we probably
+ ;; don't want.
+ (with-output-to-port
+ (%make-void-port "w")
+ (lambda ()
+ (reset-timestamps real-path)))
+ (deduplicate real-path store-dir hash)
+ ;; If we've made it this far without an exception, I guess we've
+ ;; probably succeeded?
+ #t))))
;;;
- branch guile-daemon created (now a647f6e), Caleb Ristvedt, 2017/06/12
- 04/09: guix: sql.scm: split into generic and store-specific parts., Caleb Ristvedt, 2017/06/12
- 08/09: guix: register-path: return #t on success.,
Caleb Ristvedt <=
- 06/09: guix: register-path: reset timestamps after registering., Caleb Ristvedt, 2017/06/12
- 01/09: guix: register-path: Implement prototype in scheme., Caleb Ristvedt, 2017/06/12
- 05/09: guix: register-path: use new %store-database-directory, Caleb Ristvedt, 2017/06/12
- 03/09: .dir-locals.el: properly indent sql macros., Caleb Ristvedt, 2017/06/12
- 07/09: guix: register-path: do deduplication., Caleb Ristvedt, 2017/06/12
- 09/09: deduplication: new module., Caleb Ristvedt, 2017/06/12
- 02/09: guix: register-path: Honor environment variables., Caleb Ristvedt, 2017/06/12