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.
This commit is contained in:
parent
f49e913188
commit
b1fb663404
2 changed files with 46 additions and 28 deletions
|
@ -42,6 +42,8 @@
|
||||||
#:autoload (guix store roots) (gc-roots)
|
#:autoload (guix store roots) (gc-roots)
|
||||||
#:use-module ((guix build utils)
|
#:use-module ((guix build utils)
|
||||||
#:select (directory-exists? mkdir-p))
|
#: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 format)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 regex)
|
#:use-module (ice-9 regex)
|
||||||
|
@ -876,7 +878,15 @@ processed, #f otherwise."
|
||||||
(package-version item)
|
(package-version item)
|
||||||
(manifest-entry-version entry))))))
|
(manifest-entry-version entry))))))
|
||||||
|
|
||||||
;; First, process roll-backs, generation removals, etc.
|
|
||||||
|
;; 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
|
(for-each (match-lambda
|
||||||
((key . arg)
|
((key . arg)
|
||||||
(and=> (assoc-ref %actions key)
|
(and=> (assoc-ref %actions key)
|
||||||
|
@ -905,7 +915,7 @@ processed, #f otherwise."
|
||||||
#:allow-collisions? allow-collisions?
|
#:allow-collisions? allow-collisions?
|
||||||
#:bootstrap? bootstrap?
|
#:bootstrap? bootstrap?
|
||||||
#:use-substitutes? substitutes?
|
#:use-substitutes? substitutes?
|
||||||
#:dry-run? dry-run?))))
|
#:dry-run? dry-run?)))))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
|
|
|
@ -33,7 +33,7 @@ profile="t-profile-$$"
|
||||||
tmpfile="t-guix-package-file-$$"
|
tmpfile="t-guix-package-file-$$"
|
||||||
rm -f "$profile" "$tmpfile"
|
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.
|
# Use `-e' with a non-package expression.
|
||||||
if guix package --bootstrap -e +;
|
if guix package --bootstrap -e +;
|
||||||
|
@ -452,3 +452,11 @@ rm -rf "$module_dir"
|
||||||
# Make sure we can see user profiles.
|
# Make sure we can see user profiles.
|
||||||
guix package --list-profiles | grep "$profile"
|
guix package --list-profiles | grep "$profile"
|
||||||
guix package --list-profiles | grep '\.guix-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
|
||||||
|
|
Reference in a new issue