store: Add 'with-store' convenience macro.

* guix/store.scm (with-store): New macro.
This commit is contained in:
Ludovic Courtès 2014-01-19 23:03:43 +01:00
parent 045111e10c
commit ce4a482983
2 changed files with 13 additions and 0 deletions

View file

@ -18,6 +18,7 @@
(eval . (put 'manifest-entry 'scheme-indent-function 0)) (eval . (put 'manifest-entry 'scheme-indent-function 0))
(eval . (put 'manifest-pattern 'scheme-indent-function 0)) (eval . (put 'manifest-pattern 'scheme-indent-function 0))
(eval . (put 'substitute-keyword-arguments 'scheme-indent-function 1)) (eval . (put 'substitute-keyword-arguments 'scheme-indent-function 1))
(eval . (put 'with-store 'scheme-indent-function 1))
(eval . (put 'with-error-handling 'scheme-indent-function 0)) (eval . (put 'with-error-handling 'scheme-indent-function 0))
(eval . (put 'with-mutex 'scheme-indent-function 1)) (eval . (put 'with-mutex 'scheme-indent-function 1))
(eval . (put 'with-atomic-file-output 'scheme-indent-function 1)) (eval . (put 'with-atomic-file-output 'scheme-indent-function 1))

View file

@ -53,6 +53,7 @@ (define-module (guix store)
open-connection open-connection
close-connection close-connection
with-store
set-build-options set-build-options
valid-path? valid-path?
query-path-hash query-path-hash
@ -323,6 +324,17 @@ (define (close-connection server)
"Close the connection to SERVER." "Close the connection to SERVER."
(close (nix-server-socket server))) (close (nix-server-socket server)))
(define-syntax-rule (with-store store exp ...)
"Bind STORE to an open connection to the store and evaluate EXPs;
automatically close the store when the dynamic extent of EXP is left."
(let ((store (open-connection)))
(dynamic-wind
(const #f)
(lambda ()
exp ...)
(lambda ()
(false-if-exception (close-connection store))))))
(define current-build-output-port (define current-build-output-port
;; The port where build output is sent. ;; The port where build output is sent.
(make-parameter (current-error-port))) (make-parameter (current-error-port)))