From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Lepiller Subject: bug#36375: [PATCH] Re: =?UTF-8?Q?=E2=80=98guix_?= =?UTF-8?Q?package=E2=80=99?= should lock the profile Date: Fri, 25 Oct 2019 21:44:51 +0200 Message-ID: <20191025214451.284c3530@sybil.lepiller.eu> References: <875zotn4c1.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="MP_/NjXHDtYF7MwzvaUEg6ae_qD" Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:58699) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO5XA-0001D8-T5 for bug-guix@gnu.org; Fri, 25 Oct 2019 15:46:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iO5X8-0000PU-4Q for bug-guix@gnu.org; Fri, 25 Oct 2019 15:46:04 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:58781) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iO5X8-0000PN-0A for bug-guix@gnu.org; Fri, 25 Oct 2019 15:46:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iO5X7-0000D4-Su for bug-guix@gnu.org; Fri, 25 Oct 2019 15:46:01 -0400 Sender: "Debbugs-submit" Resent-Message-ID: Received: from eggs.gnu.org ([2001:470:142:3::10]:58540) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iO5WD-0007nj-96 for bug-Guix@gnu.org; Fri, 25 Oct 2019 15:45:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iO5WB-0007xn-Lq for bug-Guix@gnu.org; Fri, 25 Oct 2019 15:45:04 -0400 In-Reply-To: <875zotn4c1.fsf@gnu.org> List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+gcggb-bug-guix=m.gmane.org@gnu.org Sender: "bug-Guix" To: Ludovic =?UTF-8?Q?Court=C3=A8s?= Cc: bug-Guix@gnu.org --MP_/NjXHDtYF7MwzvaUEg6ae_qD Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Le Tue, 25 Jun 2019 16:10:22 +0200, Ludovic Court=C3=A8s a =C3=A9crit : > The article at > mentions > things like: >=20 > For instance, after installing Icecat, I installed a few other > desktop programs and then found Icecat had disappeared from my path > again. >=20 > It=E2=80=99s likely that the person ran several =E2=80=98guix package=E2= =80=99 commands in > parallel, and that one undoed the effects of the other. >=20 > Julien suggested that =E2=80=98guix package=E2=80=99 could grab a lock fi= le, and I > guess it could simply error out when the lock is already taken. >=20 > Ludo=E2=80=99. Hi! attached is a patch for guix package to grab a lock file. Note that I'm using flock, so it won't work on NFS shares. The other option would be to use fcntl but guile doesn't seem to implement the locking function from it. --MP_/NjXHDtYF7MwzvaUEg6ae_qD Content-Type: text/x-patch Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=0001-guix-package-lock-profiles-when-processing-them.patch >From 987e9711f1fa6bfd270e48ee5624f69696e7e5c4 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Fri, 25 Oct 2019 21:39:21 +0200 Subject: [PATCH] guix: package: lock profiles when processing them. * guix/scripts/package.scm (process-actions): Get a per-profile lock to prevent concurrent actions on profiles. --- guix/scripts/package.scm | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm index 1a58d43e5c..e4f0f416f5 100644 --- a/guix/scripts/package.scm +++ b/guix/scripts/package.scm @@ -876,7 +876,17 @@ processed, #f otherwise." (package-version item) (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. + (define lock-file (open (string-append profile ".lock") O_CREAT)) + (catch 'system-error + (lambda _ + (flock lock-file (logior LOCK_EX LOCK_NB))) + (lambda (key . args) + (leave (G_ "profile ~a is being locked by another guix process.~%") + profile))) + + ;; Then, process roll-backs, generation removals, etc. (for-each (match-lambda ((key . arg) (and=> (assoc-ref %actions key) @@ -905,7 +915,10 @@ processed, #f otherwise." #:allow-collisions? allow-collisions? #:bootstrap? bootstrap? #:use-substitutes? substitutes? - #:dry-run? dry-run?)))) + #:dry-run? dry-run?))) + + ;; Finaly, close the lock file + (close lock-file)) ;;; -- 2.22.0 --MP_/NjXHDtYF7MwzvaUEg6ae_qD--