store: Add 'with-store' convenience macro.
authorLudovic Courtès <ludo@gnu.org>
Sun, 19 Jan 2014 22:03:43 +0000 (23:03 +0100)
committerLudovic Courtès <ludo@gnu.org>
Thu, 23 Jan 2014 23:01:49 +0000 (00:01 +0100)
* guix/store.scm (with-store): New macro.

.dir-locals.el
guix/store.scm

index 87cdaae..03d9a4e 100644 (file)
@@ -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))
index 393eee8..ede6434 100644 (file)
@@ -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)))