diff options
author | Ludovic Courtès <ludo@gnu.org> | 2019-11-29 14:53:22 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2019-11-29 15:54:20 +0100 |
commit | 55e1dfa4dd189e010c541e3997b65434c702b4a5 (patch) | |
tree | 24cfeb92c7778694f1c61d1e231afeaf43d37453 /guix/ui.scm | |
parent | 403604c31e1a914d338f62d222081be5f62e0520 (diff) | |
download | patches-55e1dfa4dd189e010c541e3997b65434c702b4a5.tar patches-55e1dfa4dd189e010c541e3997b65434c702b4a5.tar.gz |
ui: Factorize 'with-profile-lock'.
* guix/ui.scm (profile-lock-handler, profile-lock-file): New
procedures.
(with-profile-lock): New macro.
* guix/scripts/package.scm (process-actions): Use 'with-profile-lock'
instead of 'with-file-lock/no-wait'.
* guix/scripts/pull.scm (guix-pull): Likewise.
Diffstat (limited to 'guix/ui.scm')
-rw-r--r-- | guix/ui.scm | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/guix/ui.scm b/guix/ui.scm index b7d5516b5a..f4aa6e291e 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -47,8 +47,8 @@ #:use-module ((guix licenses) #:select (license? license-name license-uri)) #:use-module ((guix build syscalls) - #:select (free-disk-space terminal-columns - terminal-rows)) + #:select (free-disk-space terminal-columns terminal-rows + with-file-lock/no-wait)) #:use-module ((guix build utils) ;; XXX: All we need are the bindings related to ;; '&invoke-error'. However, to work around the bug described @@ -119,6 +119,7 @@ package-relevance display-search-results + with-profile-lock string->generations string->duration matching-generations @@ -1663,6 +1664,21 @@ DURATION-RELATION with the current time." (display-diff profile gen1 gen2)) +(define (profile-lock-handler profile errno . _) + "Handle failure to acquire PROFILE's lock." + (leave (G_ "profile ~a is locked by another process~%") + profile)) + +(define profile-lock-file + (cut string-append <> ".lock")) + +(define-syntax-rule (with-profile-lock profile exp ...) + "Grab PROFILE's lock and evaluate EXP... Call 'leave' if the lock is +already taken." + (with-file-lock/no-wait (profile-lock-file profile) + (cut profile-lock-handler profile <...>) + exp ...)) + (define (display-profile-content profile number) "Display the packages in PROFILE, generation NUMBER, in a human-readable way." |