From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id yLtJMtBx/WZh1wAAqHPOHw:P1 (envelope-from ) for ; Wed, 02 Oct 2024 16:16:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id yLtJMtBx/WZh1wAAqHPOHw (envelope-from ) for ; Wed, 02 Oct 2024 18:16:16 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=uovg4rfE; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=nSVzVuLy; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1727885776; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=f4RJpQpVEjae885n9JkwbhIGJEFqGEquJ1wbQC1ah8Q=; b=kVWKFx4vq2wfqGsHGAGReehAjHhsayp3sckfdR/psK2CBTkGcVinCnrvFFkxbx45/QUn4Q Q+NsTCqeQerLaCrRftI+9HeeeuGtqqRa2IXU000SEE9IEd6GxysDmDJLZmQR6fgfcqNYhu GQKiH/9AOkusye+01Ix7I//owQKzSgSTia9GtzdIBe68Ua3AZD5EVCNF3U85cxz9Qm5iIc oXlDe+OudTn89+K3kt7HsRsQfZ6r86nC3njb+yIYHO3ZbdABI/oVWPS0musfIJyIB520tv BQ2g73hVZZwGOGohY4iwIh2DXkBhUyyDQii8zpgtsrx9RjhazO2dku36kdFOZg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=uovg4rfE; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=nSVzVuLy; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1727885776; a=rsa-sha256; cv=none; b=eJOTYOCztLmtnBvA+SP1wGhlVEqbGogZ4tI8CXw8yMyUYlPtxvVPOg+ogR0pg5KGyAVE1D MH5QwwgeoF+3QucD9iyW7Vrjy3UEkUUAOO1nholaraB0+EzuZPqh4OwRlJceAp+eb+7adg aO38mTI5ftXgpq5HrLBzlklBMiQ4BE9NP3HtvmetWvJlvl2gjM8OSUL3TPM4Pq0msNP629 qGUstoncwgpjK8ijNtonWuoA1NQ0pRa00Edwuo2/j0jERxgEmUuZbKiCDTghREK+jYGgH0 rcoYtCBCBvq/j7FEZNORy3sJhayg+aMQglNGyEXVXtkJQQMTqc08tGWpjsjp0g== 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 EF2907BF54 for ; Wed, 02 Oct 2024 18:16:14 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sw21F-0005bH-HR; Wed, 02 Oct 2024 12:16:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sw21D-0005ay-7T for guix-patches@gnu.org; Wed, 02 Oct 2024 12:16:03 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sw21B-0003ff-VG for guix-patches@gnu.org; Wed, 02 Oct 2024 12:16:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=f4RJpQpVEjae885n9JkwbhIGJEFqGEquJ1wbQC1ah8Q=; b=uovg4rfEKUXuk6GswV4gAtPXxKL1QSQ66jsibI7tJKZRR662c93gUFRY473tduFU8SRWzPDLBLhKMW1r2TJoSNxw21NQ4Q5RDpKFCk93qzIsKvdwO9pFCH8LVW/aJoRM0TdMqczqWx8KoSBLB+Qjcw1sU2ve+sOGHPYCMo+G8wQvr7sarka5uavmmvpbz1/s8mxT7YiWlxcoANqY9qVlqYv2ycx9I59n7j5fgO1SyYgoQN7VDSoH1viEIXW/+vYlCkhGGbGK7p4X/iTO4L1d0nOsNRhabBDCzpUGtDf9+j7UAzE0tMMbQYfFQ/2m3vcuB0BQfvMzizEWjLXhdZdAXw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sw21C-0001fm-A4 for guix-patches@gnu.org; Wed, 02 Oct 2024 12:16:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72867] [PATCH v6] gexp: Make 'local-file' follow symlinks. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Wed, 02 Oct 2024 16:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72867 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Nigko Yerden Cc: Josselin Poiret , Simon Tournier , Mathieu Othacehe , Tobias Geerinckx-Rice , pelzflorian , Christopher Baines , Attila Lendvai , 72867@debbugs.gnu.org Received: via spool by 72867-submit@debbugs.gnu.org id=B72867.17278857606423 (code B ref 72867); Wed, 02 Oct 2024 16:16:02 +0000 Received: (at 72867) by debbugs.gnu.org; 2 Oct 2024 16:16:00 +0000 Received: from localhost ([127.0.0.1]:59080 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sw21A-0001fW-9U for submit@debbugs.gnu.org; Wed, 02 Oct 2024 12:16:00 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50342) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sw218-0001fA-16 for 72867@debbugs.gnu.org; Wed, 02 Oct 2024 12:15:59 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sw20y-0003bl-Bo; Wed, 02 Oct 2024 12:15:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=f4RJpQpVEjae885n9JkwbhIGJEFqGEquJ1wbQC1ah8Q=; b=nSVzVuLy8V6G6gdwk0eW VrbeIkkPqbW9N3Zic0HX4eQIu+0YVECvjdildwTkpL3lz3rYNCWq1DswpEzQNuTFtul/WuKLFywLm vvxJ8Gd4Qbbnc/SWcGcymMpiZN/O/7RlT42A0kfA/s1N8YMrnjdnpj+mzavA8yhmp3Irgfsud9jq1 C7RmjdrBt4U9foUUEp8QSyEdhnn/Ef+ZFgG4EtaenToGisqOuLsxzuWp9oi1OAiA0q14+VIwwF2HK cbF6JTv5cJTL94M6r55yF1og+Ie+9xUtqRcYTmfhzVFaiH3qNOgmVfeOVj/mTkbRvcgoRwLogLkdN xxa/Gz23Bma1gw==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= In-Reply-To: <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@gmail.com> (Nigko Yerden's message of "Thu, 26 Sep 2024 12:07:56 +0500") References: <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@gmail.com> Date: Wed, 02 Oct 2024 18:15:45 +0200 Message-ID: <87bk02wkem.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 1.22 X-Spam-Score: 1.22 X-Migadu-Queue-Id: EF2907BF54 X-TUID: S4bp6T3yy+we Hi Nigko, Nigko Yerden skribis: > Fix > via making 'current-source-directory' always follow symlinks. > > * guix/utils.scm (absolute-dirname, current-source-directory): Make > them follow symlinks. > * tests/gexp.scm ("local-file, load through symlink"): New test. > > Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59 [...] > --- a/guix/utils.scm > +++ b/guix/utils.scm > @@ -1121,11 +1121,7 @@ (define absolute-dirname > (match (search-path %load-path file) > (#f #f) > ((? string? file) > - ;; If there are relative names in %LOAD-PATH, FILE can be relativ= e and > - ;; needs to be canonicalized. > - (if (string-prefix? "/" file) > - (dirname file) > - (canonicalize-path (dirname file))))))) > + (dirname (canonicalize-path file)))))) Am I right that we cannot keep the =E2=80=98if=E2=80=99 here, as it would p= erform =E2=80=9Clexical=E2=80=9D dot-dot resolution instead of Unix resolution (ac= counting for symlinks), right? > @@ -1141,7 +1137,7 @@ (define-syntax current-source-directory > ;; run time rather than expansion time is necessary to allow f= iles > ;; to be moved on the file system. > (if (string-prefix? "/" file-name) > - (dirname file-name) > + (dirname (canonicalize-path file-name)) Note that =E2=80=98current-source-directory=E2=80=99 is a macro; using =E2=80=98canonicalize-path=E2=80=99 here could lead to an exception being t= hrown at macro-expansion time, if =E2=80=98file-name=E2=80=99 doesn=E2=80=99t exist.= This normally doesn=E2=80=99t happen but maybe we should handle this gracefully? The downside of these two changes is that this leads to potentially many =E2=80=98canonicalize-path=E2=80=99 calls, which are expensive (see the out= put of =E2=80=98strace=E2=80=99). This could become a problem if, for example, a = channel has many package definitions that refer to patches and auxiliary files via =E2=80=98local-file=E2=80=99. Can this be avoided?=20=20 Another issue is that it changes the semantics of =E2=80=98current-source-directory=E2=80=99 in the presence of symlinks. Th= at=E2=80=99s the whole point, but I wonder if that=E2=80=99s always desirable (see below). > +(test-assert "local-file, load through symlink" > + ;; See . > + (call-with-temporary-directory > + (lambda (tmp-dir) > + (chdir tmp-dir) Below is another way to write this test: 1. Using =E2=80=98with-directory-excursion=E2=80=99 so the current direct= ory is switched back to what it was after this test. 2. Using =E2=80=98resolve-module=E2=80=99 instead of =E2=80=98use-modules= =E2=80=99 (the latter should only be used at the top level). 3. Tweaked the comments. --8<---------------cut here---------------start------------->8--- (test-assert "local-file, load through symlink" ;; See . (call-with-temporary-directory (lambda (tmp-dir) (with-directory-excursion tmp-dir ;; create content file (call-with-output-file "content" (lambda (port) (display "Hi!" port))) ;; Create a module that calls 'local-file' with the "content" file a= nd ;; returns its absolute file name. An error is raised if the "conte= nt" ;; file can't be found. (call-with-output-file "test-local-file.scm" (lambda (port) (display "\ (define-module (test-local-file) #:use-module (guix gexp)) (define file (local-file \"content\" \"test-file\")) (local-file-absolute-file-name file)" port))) (mkdir "dir") (symlink "../test-local-file.scm" "dir/test-local-file.scm") ;; 'local-file' in turn calls 'current-source-directory' which has an ;; 'if' branching condition depending on whether 'file-name' is ;; absolute or relative file name. To test both of these branches we ;; execute 'test-local-file.scm' symlink first as a module (correspo= nds ;; to relative file name): (dynamic-wind (lambda () (set! %load-path (cons "dir" %load-path))) (lambda () (resolve-module '(test-local-file) #:ensure #f)) (lambda () (set! %load-path (cdr %load-path)))) ;; and then as a regular code (corresponds to absolute file name): (load (string-append tmp-dir "/dir/test-local-file.scm")))))) --8<---------------cut here---------------end--------------->8--- But=E2=80=A6 here we have: /tmpdir | +--- test-local-file.scm +--- content +--- dir | +--- test-local-file.scm To me, it=E2=80=99s not unreasonable for (local-file "content") to fail when loading =E2=80=98dir/test-local-file.scm=E2=80=99. I would say that this i= s what most people would expect. So maybe we should go back to the actual use case and take a step back: https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html I didn=E2=80=99t hit this problem, presumably because my GUILE_LOAD_PATH do= es not contain =E2=80=98~/.config/guix/current/share/guile/site/3.0=E2=80=99 (= I use Guile and Shepherd as channels=C2=B9). Is there anything else we can do to address this? Sorry for providing more questions that answers! Thanks, Ludo=E2=80=99. =C2=B9 (append (list (channel (name 'shepherd) (url "https://git.savannah.gnu.org/git/shepherd.git") (branch "devel") (introduction (make-channel-introduction "788a6d6f1d5c170db68aa4bbfb77024fdc468ed3" (openpgp-fingerprint "3CE464558A84FDC69DB40CFB090B11993D9AEBB5")))) (channel (name 'guile) (url "https://git.savannah.gnu.org/git/guile.git") (branch "main"))) %default-channels)