[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
108/184: guix: Add file-locking with no wait.
From: |
guix-commits |
Subject: |
108/184: guix: Add file-locking with no wait. |
Date: |
Wed, 27 Nov 2019 14:37:10 -0500 (EST) |
kkebreau pushed a commit to branch wip-gnome-updates
in repository guix.
commit 9453497c54141a8b514c71f93765e1c57380c578
Author: Julien Lepiller <address@hidden>
Date: Thu Nov 7 21:50:54 2019 +0100
guix: Add file-locking with no wait.
* guix/build/syscalls.scm (with-file-lock/no-wait): New procedure.
(lock-file): Take a #:wait? key.
---
guix/build/syscalls.scm | 35 +++++++++++++++++++++++++++++++++--
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index bbf2531..a5a9c92 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -80,6 +80,7 @@
lock-file
unlock-file
with-file-lock
+ with-file-lock/no-wait
set-thread-name
thread-name
@@ -1087,10 +1088,10 @@ exception if it's already taken."
;; Presumably we got EAGAIN or so.
(throw 'flock-error err))))))
-(define (lock-file file)
+(define* (lock-file file #:key (wait? #t))
"Wait and acquire an exclusive lock on FILE. Return an open port."
(let ((port (open-file file "w0")))
- (fcntl-flock port 'write-lock)
+ (fcntl-flock port 'write-lock #:wait? wait?)
port))
(define (unlock-file port)
@@ -1119,10 +1120,40 @@ exception if it's already taken."
(when port
(unlock-file port))))))
+(define (call-with-file-lock/no-wait file thunk handler)
+ (let ((port (catch #t
+ (lambda ()
+ (lock-file file #:wait? #f))
+ (lambda (key . args)
+ (match key
+ ('flock-error
+ (handler args))
+ ('system-error
+ ;; When using the statically-linked Guile in the initrd,
+ ;; 'fcntl-flock' returns ENOSYS unconditionally. Ignore
+ ;; that error since we're typically the only process
running
+ ;; at this point.
+ (if (= ENOSYS (system-error-errno (cons key args)))
+ #f
+ (apply throw args)))
+ (_ (apply throw key args)))))))
+ (dynamic-wind
+ (lambda ()
+ #t)
+ thunk
+ (lambda ()
+ (when port
+ (unlock-file port))))))
+
(define-syntax-rule (with-file-lock file exp ...)
"Wait to acquire a lock on FILE and evaluate EXP in that context."
(call-with-file-lock file (lambda () exp ...)))
+(define-syntax-rule (with-file-lock/no-wait file handler exp ...)
+ "Try to acquire a lock on FILE and evaluate EXP in that context. Execute
+handler if the lock is already held by another process."
+ (call-with-file-lock/no-wait file (lambda () exp ...) handler))
+
;;;
;;; Miscellaneous, aka. 'prctl'.
- 113/184: gnu: Add gnome-shell-extension-noannoyance., (continued)
- 113/184: gnu: Add gnome-shell-extension-noannoyance., guix-commits, 2019/11/27
- 119/184: gnu: python-latexcodec: Update to 1.0.7., guix-commits, 2019/11/27
- 62/184: gnu: network-manager: Update to 1.18.4., guix-commits, 2019/11/27
- 68/184: gnu: linux-libre: Update to 5.3.9., guix-commits, 2019/11/27
- 70/184: gnu: devhelp: Don't create icon cache., guix-commits, 2019/11/27
- 71/184: gnu: eog: Don't create icon cache., guix-commits, 2019/11/27
- 83/184: services: Make it possible to include dynamic modules in nginx., guix-commits, 2019/11/27
- 87/184: gnu: libdvdnav: Update to 6.0.1., guix-commits, 2019/11/27
- 92/184: gnu: Fix deprecation of monolithic Qt 5.x package., guix-commits, 2019/11/27
- 104/184: gnu: fcitx-configtool: Don't use NAME in source URI., guix-commits, 2019/11/27
- 108/184: guix: Add file-locking with no wait.,
guix-commits <=
- 126/184: gnu: neovim: Update to 0.4.3., guix-commits, 2019/11/27
- 158/184: gnu: faad2: Use HTTPS home page., guix-commits, 2019/11/27
- 160/184: gnu: cgal: Update to 4.14.2., guix-commits, 2019/11/27
- 180/184: gnu: zita-convolver: Update to 4.0.3., guix-commits, 2019/11/27
- 115/184: gnu: python-psutil: Update to 5.6.5., guix-commits, 2019/11/27
- 122/184: ui: Emit hyperlinks for 'license' in package search results., guix-commits, 2019/11/27
- 134/184: gnu: Add perl-moox-strictconstructor., guix-commits, 2019/11/27
- 151/184: gnu: babl: Update to 0.1.72., guix-commits, 2019/11/27
- 156/184: gnu: xfce4-whiskermenu-plugin: Update to 2.3.4., guix-commits, 2019/11/27
- 150/184: gnu: fvwm: Update to 2.6.9., guix-commits, 2019/11/27