[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
109/184: guix: package: lock profiles when processing them.
From: |
guix-commits |
Subject: |
109/184: guix: package: lock profiles when processing them. |
Date: |
Wed, 27 Nov 2019 14:37:10 -0500 (EST) |
kkebreau pushed a commit to branch wip-gnome-updates
in repository guix.
commit d9c8660df6f8837ed14fa6406e23694fbca07b3e
Author: Julien Lepiller <address@hidden>
Date: Fri Oct 25 21:39:21 2019 +0200
guix: package: lock profiles when processing them.
* guix/scripts/package.scm (process-actions): Get a per-profile lock to
prevent concurrent actions on profiles.
* tests/guix-package.sh: Add test.
---
guix/scripts/package.scm | 70 +++++++++++++++++++++++++++---------------------
tests/guix-package.sh | 10 ++++++-
2 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 1a58d43..bcd03a1 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -42,6 +42,8 @@
#:autoload (guix store roots) (gc-roots)
#:use-module ((guix build utils)
#:select (directory-exists? mkdir-p))
+ #:use-module ((guix build syscalls)
+ #:select (with-file-lock/no-wait))
#:use-module (ice-9 format)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
@@ -876,36 +878,44 @@ processed, #f otherwise."
(package-version item)
(manifest-entry-version entry))))))
- ;; First, process roll-backs, generation removals, etc.
- (for-each (match-lambda
- ((key . arg)
- (and=> (assoc-ref %actions key)
- (lambda (proc)
- (proc store profile arg opts
- #:dry-run? dry-run?)))))
- opts)
-
- ;; Then, process normal package removal/installation/upgrade.
- (let* ((manifest (profile-manifest profile))
- (step1 (options->removable opts manifest
- (manifest-transaction)))
- (step2 (options->installable opts manifest step1))
- (step3 (manifest-transaction
- (inherit step2)
- (install (map transform-entry
- (manifest-transaction-install step2)))))
- (new (manifest-perform-transaction manifest step3)))
-
- (warn-about-old-distro)
-
- (unless (manifest-transaction-null? step3)
- (show-manifest-transaction store manifest step3
- #:dry-run? dry-run?)
- (build-and-use-profile store profile new
- #:allow-collisions? allow-collisions?
- #:bootstrap? bootstrap?
- #:use-substitutes? substitutes?
- #:dry-run? dry-run?))))
+
+ ;; First, acquire a lock on the profile, to ensure only one guix process
+ ;; is modifying it at a time.
+ (with-file-lock/no-wait (string-append profile ".lock")
+ (lambda (key . args)
+ (leave (G_ "profile ~a is locked by another process~%")
+ profile))
+
+ ;; Then, process roll-backs, generation removals, etc.
+ (for-each (match-lambda
+ ((key . arg)
+ (and=> (assoc-ref %actions key)
+ (lambda (proc)
+ (proc store profile arg opts
+ #:dry-run? dry-run?)))))
+ opts)
+
+ ;; Then, process normal package removal/installation/upgrade.
+ (let* ((manifest (profile-manifest profile))
+ (step1 (options->removable opts manifest
+ (manifest-transaction)))
+ (step2 (options->installable opts manifest step1))
+ (step3 (manifest-transaction
+ (inherit step2)
+ (install (map transform-entry
+ (manifest-transaction-install step2)))))
+ (new (manifest-perform-transaction manifest step3)))
+
+ (warn-about-old-distro)
+
+ (unless (manifest-transaction-null? step3)
+ (show-manifest-transaction store manifest step3
+ #:dry-run? dry-run?)
+ (build-and-use-profile store profile new
+ #:allow-collisions? allow-collisions?
+ #:bootstrap? bootstrap?
+ #:use-substitutes? substitutes?
+ #:dry-run? dry-run?)))))
;;;
diff --git a/tests/guix-package.sh b/tests/guix-package.sh
index 0de30bf..7ad0699 100644
--- a/tests/guix-package.sh
+++ b/tests/guix-package.sh
@@ -33,7 +33,7 @@ profile="t-profile-$$"
tmpfile="t-guix-package-file-$$"
rm -f "$profile" "$tmpfile"
-trap 'rm -f "$profile" "$profile-"[0-9]* "$tmpfile"; rm -rf "$module_dir"
t-home-'"$$" EXIT
+trap 'rm -f "$profile" "$profile.lock" "$profile-"[0-9]* "$tmpfile"; rm -rf
"$module_dir" t-home-'"$$" EXIT
# Use `-e' with a non-package expression.
if guix package --bootstrap -e +;
@@ -452,3 +452,11 @@ rm -rf "$module_dir"
# Make sure we can see user profiles.
guix package --list-profiles | grep "$profile"
guix package --list-profiles | grep '\.guix-profile'
+
+# Make sure we can properly lock a profile.
+mkdir "$module_dir"
+echo '(sleep 60)' > "$module_dir/manifest.scm"
+guix package -m "$module_dir/manifest.scm" -p "$module_dir/profile" &
+pid=$!
+if guix install emacs -p "$module_dir/profile"; then kill $pid; false; else
true; fi
+kill $pid
- 184/184: Merge branch 'master' into wip-gnome-updates, (continued)
- 184/184: Merge branch 'master' into wip-gnome-updates, guix-commits, 2019/11/27
- 88/184: gnu: libdvdread: Update to 6.0.2., guix-commits, 2019/11/27
- 120/184: gnu: botan: Update to 2.12.1., guix-commits, 2019/11/27
- 117/184: gnu: perl-data-compare: Update to 1.27., guix-commits, 2019/11/27
- 114/184: gnu: python-astroid: Update to 2.3.3., guix-commits, 2019/11/27
- 127/184: gnu: signify: Update to 27., guix-commits, 2019/11/27
- 67/184: gnu: linux-libre@4.19: Update to 4.19.82., guix-commits, 2019/11/27
- 105/184: gnu: certbot, python-acme: Update to 0.40.1., guix-commits, 2019/11/27
- 106/184: news: Add 'de' translation., guix-commits, 2019/11/27
- 107/184: services: mpd: Connect to the user's PulseAudio socket., guix-commits, 2019/11/27
- 109/184: guix: package: lock profiles when processing them.,
guix-commits <=
- 118/184: gnu: python-mpi4py: Update to 3.0.3., guix-commits, 2019/11/27
- 128/184: gnu: miniupnpc: Don't use NAME in source URI., guix-commits, 2019/11/27
- 148/184: gnu: qtractor: Update to 0.9.11., guix-commits, 2019/11/27
- 147/184: gnu: youtube-dl: Update to 2019.11.05., guix-commits, 2019/11/27
- 124/184: build: Warn about etc/indent-code.el when Emacs is absent., guix-commits, 2019/11/27
- 138/184: services: hpcguix-web: Explicitly import (guix build utils)., guix-commits, 2019/11/27
- 136/184: gnu: perl-class-inspector: Update to 1.36., guix-commits, 2019/11/27
- 125/184: gnu: Add homebank., guix-commits, 2019/11/27
- 135/184: gnu: parcimonie: Update to 0.11.0., guix-commits, 2019/11/27
- 133/184: gnu: fribidi: Fix CVE-2019-18397., guix-commits, 2019/11/27