diff options
author | Ludovic Courtès <ludo@gnu.org> | 2014-01-19 23:03:43 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2014-01-24 00:01:49 +0100 |
commit | ce4a482983abaf7090d098cdda973139cefb56b7 (patch) | |
tree | 63d1e8bb1ae0e1119d958fd1163a14251691b3b8 | |
parent | 045111e10c0197f1a235bb886df2e446285a6f70 (diff) | |
download | guix-ce4a482983abaf7090d098cdda973139cefb56b7.tar guix-ce4a482983abaf7090d098cdda973139cefb56b7.tar.gz |
store: Add 'with-store' convenience macro.
* guix/store.scm (with-store): New macro.
-rw-r--r-- | .dir-locals.el | 1 | ||||
-rw-r--r-- | guix/store.scm | 12 |
2 files changed, 13 insertions, 0 deletions
diff --git a/.dir-locals.el b/.dir-locals.el index 87cdaae807..03d9a4ec8d 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -18,6 +18,7 @@ (eval . (put 'manifest-entry 'scheme-indent-function 0)) (eval . (put 'manifest-pattern 'scheme-indent-function 0)) (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-mutex 'scheme-indent-function 1)) (eval . (put 'with-atomic-file-output 'scheme-indent-function 1)) diff --git a/guix/store.scm b/guix/store.scm index 393eee8d1b..ede64341c5 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -53,6 +53,7 @@ open-connection close-connection + with-store set-build-options valid-path? query-path-hash @@ -323,6 +324,17 @@ operate, should the disk become full. Return a server object." "Close the connection to 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 ;; The port where build output is sent. (make-parameter (current-error-port))) |