syscalls: 'with-file-lock' re-grabs lock when reentering its dynamic extent.
* guix/build/syscalls.scm (call-with-file-lock) (call-with-file-lock/no-wait): Initialize PORT in the 'dynamic-wind' "in" handler. This allows us to re-enter a captured continuation and have the lock grabbed anew.master
parent
1550db6fd4
commit
9a067fe7ee
|
@ -1104,7 +1104,11 @@ exception if it's already taken."
|
||||||
#t)
|
#t)
|
||||||
|
|
||||||
(define (call-with-file-lock file thunk)
|
(define (call-with-file-lock file thunk)
|
||||||
(let ((port (catch 'system-error
|
(let ((port #f))
|
||||||
|
(dynamic-wind
|
||||||
|
(lambda ()
|
||||||
|
(set! port
|
||||||
|
(catch 'system-error
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(lock-file file))
|
(lock-file file))
|
||||||
(lambda args
|
(lambda args
|
||||||
|
@ -1115,16 +1119,17 @@ exception if it's already taken."
|
||||||
(if (= ENOSYS (system-error-errno args))
|
(if (= ENOSYS (system-error-errno args))
|
||||||
#f
|
#f
|
||||||
(apply throw args))))))
|
(apply throw args))))))
|
||||||
(dynamic-wind
|
|
||||||
(lambda ()
|
|
||||||
#t)
|
|
||||||
thunk
|
thunk
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(when port
|
(when port
|
||||||
(unlock-file port))))))
|
(unlock-file port))))))
|
||||||
|
|
||||||
(define (call-with-file-lock/no-wait file thunk handler)
|
(define (call-with-file-lock/no-wait file thunk handler)
|
||||||
(let ((port (catch #t
|
(let ((port #f))
|
||||||
|
(dynamic-wind
|
||||||
|
(lambda ()
|
||||||
|
(set! port
|
||||||
|
(catch #t
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(lock-file file #:wait? #f))
|
(lock-file file #:wait? #f))
|
||||||
(lambda (key . args)
|
(lambda (key . args)
|
||||||
|
@ -1142,9 +1147,6 @@ exception if it's already taken."
|
||||||
#f
|
#f
|
||||||
(apply throw key args)))
|
(apply throw key args)))
|
||||||
(_ (apply throw key args)))))))
|
(_ (apply throw key args)))))))
|
||||||
(dynamic-wind
|
|
||||||
(lambda ()
|
|
||||||
#t)
|
|
||||||
thunk
|
thunk
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(when port
|
(when port
|
||||||
|
|
Reference in New Issue