From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id kPRoAw+1BGCUXgAA0tVLHw (envelope-from ) for ; Sun, 17 Jan 2021 22:07:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id uLvOOg61BGDybwAAB5/wlQ (envelope-from ) for ; Sun, 17 Jan 2021 22:07:10 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4F4299403C5 for ; Sun, 17 Jan 2021 22:07:10 +0000 (UTC) Received: from localhost ([::1]:40740 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1GCT-0001li-00 for larch@yhetil.org; Sun, 17 Jan 2021 17:07:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34032) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l1GCM-0001la-3y for bug-guix@gnu.org; Sun, 17 Jan 2021 17:07:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34306) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l1GCL-00026i-S6 for bug-guix@gnu.org; Sun, 17 Jan 2021 17:07:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1l1GCL-0000QS-Lp for bug-guix@gnu.org; Sun, 17 Jan 2021 17:07:01 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#45295: =?UTF-8?Q?=E2=80=9Csudo?= guix system =?UTF-8?Q?reconfigure=E2=80=9D?= triggers re-clone/update of Git checkout Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sun, 17 Jan 2021 22:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45295 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 45295@debbugs.gnu.org Received: via spool by 45295-submit@debbugs.gnu.org id=B45295.16109211821591 (code B ref 45295); Sun, 17 Jan 2021 22:07:01 +0000 Received: (at 45295) by debbugs.gnu.org; 17 Jan 2021 22:06:22 +0000 Received: from localhost ([127.0.0.1]:45852 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1GBh-0000Pb-Vk for submit@debbugs.gnu.org; Sun, 17 Jan 2021 17:06:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40802) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1l1GBf-0000PN-00 for 45295@debbugs.gnu.org; Sun, 17 Jan 2021 17:06:20 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:43481) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l1GBZ-0001kd-Rs for 45295@debbugs.gnu.org; Sun, 17 Jan 2021 17:06:13 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=47788 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1l1GBY-0005xy-QT for 45295@debbugs.gnu.org; Sun, 17 Jan 2021 17:06:13 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= References: <87mtycila0.fsf@inria.fr> Date: Sun, 17 Jan 2021 23:06:11 +0100 In-Reply-To: <87mtycila0.fsf@inria.fr> ("Ludovic =?UTF-8?Q?Court=C3=A8s?="'s message of "Thu, 17 Dec 2020 15:01:43 +0100") Message-ID: <87bldnusks.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -2.86 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 4F4299403C5 X-Spam-Score: -2.86 X-Migadu-Scanner: scn1.migadu.com X-TUID: 9TYn+/IzzAdJ --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Ludovic Court=C3=A8s skribis: > If you do, as a regular user: > > guix pull > sudo guix system reconfigure =E2=80=A6 > > the =E2=80=98guix system reconfigure=E2=80=99, as part of the downgrade-d= etection > machinery, triggers an update of the channel checkout(s) in > ~root/.cache, even though ~USER/.cache is already up-to-date. > > One way to avoid it might be to special-case the checkout cache > directory for when =E2=80=98SUDO_USER=E2=80=99 is set. Attached is a prototype that first clones/fetches from ~USER/.cache into ~root/.cache, in the hope that this avoids the need to access the upstream repo. (It requires =E2=80=98set-remote-url!=E2=80=99, which is on= ly in Guile-Git =E2=80=98master=E2=80=99.) It=E2=80=99s a bit hacky but I can=E2=80=99t think of a better way to addre= ss this issue. In particular, having root use ~USER/.cache directly is not an option: it could end up creating root-owned files there. Thoughts? Ludo=E2=80=99. --=-=-= Content-Type: text/x-patch Content-Disposition: inline diff --git a/guix/git.scm b/guix/git.scm index a5103547d3..467d199e37 100644 --- a/guix/git.scm +++ b/guix/git.scm @@ -346,10 +346,7 @@ definitely available in REPOSITORY, false otherwise." (check-out? #t) starting-commit (log-port (%make-void-port "w")) - (cache-directory - (url-cache-directory - url (%repository-cache-directory) - #:recursive? recursive?))) + (cache-directory *unspecified*)) "Update the cached checkout of URL to REF in CACHE-DIRECTORY. Return three values: the cache directory name, and the SHA1 commit (a string) corresponding to REF, and the relation of the new commit relative to STARTING-COMMIT (if @@ -381,12 +378,41 @@ it unchanged." (string-append "origin/" branch)))) (_ ref))) + (define default-cache-directory + (url-cache-directory url (%repository-cache-directory) + #:recursive? recursive?)) + + (when (and (zero? (getuid)) (getenv "SUDO_USER") + (unspecified? cache-directory)) + ;; Fetch from the sudoer's cache before attempting to reach URL. + (let* ((home (and=> (false-if-exception (getpwnam (getenv "SUDO_USER"))) + passwd:dir)) + (peer (and home (url-cache-directory + url (string-append home "/.cache/guix/checkouts") + #:recursive? recursive?)))) + (when (and peer (file-exists? peer)) + ;; Fetch from PEER. After that, the "origin" remote points to PEER, + ;; but we change it back to URL below. + (update-cached-checkout (pk 'update peer) + #:ref ref + #:recursive? recursive? + #:check-out? #f + #:cache-directory + default-cache-directory)))) + (with-libgit2 - (let* ((cache-exists? (openable-repository? cache-directory)) - (repository (if cache-exists? - (repository-open cache-directory) - (clone* url cache-directory)))) + (let* ((cache-directory (if (unspecified? cache-directory) + default-cache-directory + cache-directory)) + (cache-exists? (openable-repository? cache-directory)) + (repository (if cache-exists? + (repository-open cache-directory) + (clone* url cache-directory)))) + ;; Ensure the "origin" remote points to URL. + (set-remote-url! repository "origin" url) + ;; Only fetch remote if it has not been cloned just before. + (pk 'x cache-directory 'avail? (reference-available? repository ref)) (when (and cache-exists? (not (reference-available? repository ref))) (let ((auth-method (%make-auth-ssh-agent))) @@ -433,8 +459,6 @@ it unchanged." #:key recursive? (log-port (%make-void-port "w")) - (cache-directory - (%repository-cache-directory)) (ref '(branch . "master"))) "Return two values: the content of the git repository at URL copied into a store directory and the sha1 of the top level commit in this directory. The @@ -464,10 +488,6 @@ Log progress and checkout info to LOG-PORT." (update-cached-checkout url #:recursive? recursive? #:ref ref - #:cache-directory - (url-cache-directory url cache-directory - #:recursive? - recursive?) #:log-port log-port)) ((name) (url+commit->name url commit))) --=-=-=--