From b2c66b443bd42e05820cfb3920c96f1894820587 Mon Sep 17 00:00:00 2001 From: Caleb Ristvedt Date: Wed, 6 May 2020 11:48:21 -0500 Subject: [PATCH 1/2] nar: 'finalize-store-file' follows proper store lock protocol. * guix/nar.scm (finalize-store-file): check for deletion token when acquiring lock, write deletion token and delete lock file before releasing lock. --- guix/nar.scm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/guix/nar.scm b/guix/nar.scm index 29636aa0f8..f91af72879 100644 --- a/guix/nar.scm +++ b/guix/nar.scm @@ -82,10 +82,19 @@ REFERENCES and DERIVER. When LOCK? is true, acquire exclusive locks on TARGET before attempting to register it; otherwise, assume TARGET's locks are already held." + ;; TODO: make this reusable + (define (acquire-lock filename) + (let ((port (lock-file filename))) + (if (zero? (stat:size (stat port))) + port + (begin + (close port) + (acquire-lock filename))))) + (with-database %default-database-file db (unless (path-id db target) (let ((lock (and lock? - (lock-file (string-append target ".lock"))))) + (acquire-lock (string-append target ".lock"))))) (unless (path-id db target) ;; If FILE already exists, delete it (it's invalid anyway.) @@ -102,6 +111,9 @@ held." #:deriver deriver)) (when lock? + (delete-file (string-append target ".lock")) + (display "d" lock) + (force-output lock) (unlock-file lock)))))) (define (temporary-store-file) -- 2.26.2