summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--guix/store.scm12
-rw-r--r--tests/store.scm27
2 files changed, 34 insertions, 5 deletions
diff --git a/guix/store.scm b/guix/store.scm
index ca8c0e5ef83..1dd5c9545b9 100644
--- a/guix/store.scm
+++ b/guix/store.scm
@@ -623,14 +623,16 @@ connection. Use with care."
623(define (call-with-store proc) 623(define (call-with-store proc)
624 "Call PROC with an open store connection." 624 "Call PROC with an open store connection."
625 (let ((store (open-connection))) 625 (let ((store (open-connection)))
626 (dynamic-wind 626 (catch #t
627 (const #f)
628 (lambda () 627 (lambda ()
629 (parameterize ((current-store-protocol-version 628 (parameterize ((current-store-protocol-version
630 (store-connection-version store))) 629 (store-connection-version store)))
631 (proc store))) 630 (let ((result (proc store)))
632 (lambda () 631 (close-connection store)
633 (false-if-exception (close-connection store)))))) 632 result)))
633 (lambda (key . args)
634 (close-connection store)
635 (apply throw key args)))))
634 636
635(define-syntax-rule (with-store store exp ...) 637(define-syntax-rule (with-store store exp ...)
636 "Bind STORE to an open connection to the store and evaluate EXPs; 638 "Bind STORE to an open connection to the store and evaluate EXPs;
diff --git a/tests/store.scm b/tests/store.scm
index 0458a347465..0e80ccc2393 100644
--- a/tests/store.scm
+++ b/tests/store.scm
@@ -412,6 +412,33 @@
412 (build-derivations %store (list d2)) 412 (build-derivations %store (list d2))
413 'fail))) 413 'fail)))
414 414
415(test-equal "with-build-handler + with-store"
416 'success
417 ;; Check that STORE remains valid when the build handler invokes CONTINUE,
418 ;; even though 'with-build-handler' is outside the dynamic extent of
419 ;; 'with-store'.
420 (with-build-handler (lambda (continue store things mode)
421 (match things
422 ((drv)
423 (and (string-suffix? "thingie.drv" drv)
424 (not (port-closed?
425 (store-connection-socket store)))
426 (continue #t)))))
427 (with-store store
428 (let* ((b (add-text-to-store store "build" "echo $foo > $out" '()))
429 (s (add-to-store store "bash" #t "sha256"
430 (search-bootstrap-binary "bash"
431 (%current-system))))
432 (d (derivation store "thingie"
433 s `("-e" ,b)
434 #:env-vars `(("foo" . ,(random-text)))
435 #:sources (list b s))))
436 (build-derivations store (list d))
437
438 ;; Here STORE's socket should still be open.
439 (and (valid-path? store (derivation->output-path d))
440 'success)))))
441
415(test-assert "map/accumulate-builds" 442(test-assert "map/accumulate-builds"
416 (let* ((b (add-text-to-store %store "build" "echo $foo > $out" '())) 443 (let* ((b (add-text-to-store %store "build" "echo $foo > $out" '()))
417 (s (add-to-store %store "bash" #t "sha256" 444 (s (add-to-store %store "bash" #t "sha256"