GNU bug report logs - #72867
[PATCH] gexp: Make 'local-file' follow symlinks.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Nigko Yerden <nigko.yerden@HIDDEN>; Keywords: patch; dated Thu, 29 Aug 2024 06:10:01 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 6 Oct 2024 07:09:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Oct 06 03:09:16 2024
Received: from localhost ([127.0.0.1]:40020 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sxLOG-0005TF-Bu
	for submit <at> debbugs.gnu.org; Sun, 06 Oct 2024 03:09:16 -0400
Received: from relay.yourmailgateway.de ([188.68.61.103]:54645)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1sxLOE-0005T5-6A
 for 72867 <at> debbugs.gnu.org; Sun, 06 Oct 2024 03:09:15 -0400
Received: from mors-relay-8403.netcup.net (localhost [127.0.0.1])
 by mors-relay-8403.netcup.net (Postfix) with ESMTPS id 4XLtgR1Pmfz7yrB;
 Sun,  6 Oct 2024 09:09:07 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1728198547;
 bh=HgZN4grH38+h2XBKuv2N5LEThbOi2m2KnTh4HcoHnO4=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=ZrX9W8d87RPzzATj9sbaVPWF74wnSNWuzhvAG7rAaHmMIMDI4jIPizNcyACuR+gK9
 kNZ/xpse/Y7hUs05W2H2vaZTIJWpPmYhCnHfJ6V87nkIbqt67BGdwcqikZRYzcjNyP
 aPllXH+ktygayrjErOlcamj/MaJ4twStZ4ynxu5/QUwYuiIG0OAVnWu+D4W7EPou7z
 6zGpueoMotB8R8q8H//RvwAttPvZQFWN1plspUNPjnes/7LXx+dA9/1OreEkgzhz67
 msUKTffAMzoCNHZlFKKaOwDaUbECkA3DwAwdY4kn4n+iDOxpFak1o9QtVxN6WUHrGi
 PH6J90OPI8S2g==
Received: from policy02-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay-8403.netcup.net (Postfix) with ESMTPS id 4XLtgR11Rxz7yr4;
 Sun,  6 Oct 2024 09:09:07 +0200 (CEST)
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy02-mors.netcup.net (Postfix) with ESMTPS id 4XLtgN6hdNz8sZg;
 Sun,  6 Oct 2024 09:09:04 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id 5CF1C84277;
 Sun,  6 Oct 2024 09:08:51 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
To: Ludovic =?utf-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Subject: Re: [bug#72867] [PATCH v6] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <8734ld5nin.fsf@HIDDEN> (pelzflorian@HIDDEN's
 message of "Thu, 03 Oct 2024 15:22:56 +0200")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@HIDDEN>
 <87bk02wkem.fsf@HIDDEN> <8734ld5nin.fsf@HIDDEN>
Date: Sun, 06 Oct 2024 09:09:00 +0200
Message-ID: <87ttdpyagj.fsf@HIDDEN>
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-Rspamd-Queue-Id: 5CF1C84277
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: bdMoev58lUHYtLqmVRUQI3fEXbaxmtlGeemglET28j8VYZBbaHlmKmdR
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Josselin Poiret <dev@HIDDEN>,
 Simon Tournier <zimon.toutoune@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>,
 Tobias Geerinckx-Rice <me@HIDDEN>, Nigko Yerden <nigko.yerden@HIDDEN>,
 Christopher Baines <guix@HIDDEN>, Attila Lendvai <attila@HIDDEN>,
 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

My reply was lacking.  I accidentally deleted footnote
[1] https://git.savannah.gnu.org/cgit/guile.git/tree/

Ludovic Court=C3=A8s <ludo@HIDDEN> writes:
>> --- 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 relati=
ve 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=
 perform
> =E2=80=9Clexical=E2=80=9D dot-dot resolution instead of Unix resolution (=
accounting for
> symlinks), right?

Yes, exactly.

Does not the mlambda Ludo had put in absolute-dirname resolve all
canonicalize-path concerns?  There are many patches, but all have the
same file.

Regards,
Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 3 Oct 2024 13:23:08 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Oct 03 09:23:08 2024
Received: from localhost ([127.0.0.1]:60295 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1swLnQ-0003RP-5Y
	for submit <at> debbugs.gnu.org; Thu, 03 Oct 2024 09:23:08 -0400
Received: from relay.yourmailgateway.de ([188.68.63.162]:40635)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1swLnO-0003RD-6u
 for 72867 <at> debbugs.gnu.org; Thu, 03 Oct 2024 09:23:07 -0400
Received: from mors-relay-8201.netcup.net (localhost [127.0.0.1])
 by mors-relay-8201.netcup.net (Postfix) with ESMTPS id 4XKC6G3y02z3sr3;
 Thu,  3 Oct 2024 15:23:02 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1727961782;
 bh=fjQRthsn1PMlNJLMqU3FI4AN7Ttwtas817E8XQFysKA=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=eZGyL9b0Br/LOd5Yf8G5MqascBOy5DSmRQXEWTNkJGPSkXjfSfPHGCkVVIV9nlMyn
 D71QsNtzT7lH+La9Xaq+Xhq1YwdnVet3LyffK30T66U2pbUP5tJuTNin+n6M2Y1C1u
 7h4FGsg6wwTdTqAcxtK+HJXzTpO3LyIZiQEti176d8OCmkc7d+Xbn+r1EerVSfXdVm
 rKi/fLRNLpOvknV9cr5GIAK7j4FiL2glBa89+o1oMfRxX7h3BRRE3YC6Jra5nLuCPm
 hB4NUztuRwFV3H9Xj94BOpqTrnJBBKCogAb1TzNlhjB4dic4lTUPxjAikRd/4SscFf
 FXU1Avk0vNRmQ==
Received: from policy02-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay-8201.netcup.net (Postfix) with ESMTPS id 4XKC6G3CSDz3smx;
 Thu,  3 Oct 2024 15:23:02 +0200 (CEST)
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy02-mors.netcup.net (Postfix) with ESMTPS id 4XKC6D6lLPz8sZw;
 Thu,  3 Oct 2024 15:23:00 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id 5045383E48;
 Thu,  3 Oct 2024 15:22:48 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
To: Ludovic =?utf-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Subject: Re: [bug#72867] [PATCH v6] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <87bk02wkem.fsf@HIDDEN> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?=
 =?utf-8?Q?s?= message of "Wed, 02 Oct 2024 18:15:45 +0200")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@HIDDEN>
 <87bk02wkem.fsf@HIDDEN>
Date: Thu, 03 Oct 2024 15:22:56 +0200
Message-ID: <8734ld5nin.fsf@HIDDEN>
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-Rspamd-Queue-Id: 5045383E48
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: 71A8m3gQCg+HzpbUWHtHAQNUWTQ40RCtvRkr8Hn2pYC20j1Z+cU8yNOs
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Josselin Poiret <dev@HIDDEN>,
 Simon Tournier <zimon.toutoune@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>,
 Tobias Geerinckx-Rice <me@HIDDEN>, Nigko Yerden <nigko.yerden@HIDDEN>,
 Christopher Baines <guix@HIDDEN>, Attila Lendvai <attila@HIDDEN>,
 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello Ludo, in my opinion,

Ludovic Court=C3=A8s <ludo@HIDDEN> writes:
> To me, it=E2=80=99s not unreasonable for (local-file "content") to fail w=
hen
> loading =E2=80=98dir/test-local-file.scm=E2=80=99.  I would say that this=
 is what most
> people would expect.

Yes, the present situation is that from the real file and the symlink,
one of them will not run.

Note that the test here is the converse situation of the guile channel
[1] described in the cookbook.  There, the symlink is in the outer
directory and the real file in the inner directory, which refers to
      (source (local-file "../.." "guile-checkout"

Regards,
Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 2 Oct 2024 16:16:00 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Oct 02 12:16:00 2024
Received: from localhost ([127.0.0.1]:59080 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sw21A-0001fW-9U
	for submit <at> 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 <ludo@HIDDEN>) id 1sw218-0001fA-16
 for 72867 <at> 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 <ludo@HIDDEN>)
 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: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN>
To: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: Re: [bug#72867] [PATCH v6] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@HIDDEN>
 (Nigko Yerden's message of "Thu, 26 Sep 2024 12:07:56 +0500")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@HIDDEN>
Date: Wed, 02 Oct 2024 18:15:45 +0200
Message-ID: <87bk02wkem.fsf@HIDDEN>
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-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 72867
Cc: Josselin Poiret <dev@HIDDEN>,
 Simon Tournier <zimon.toutoune@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>,
 Tobias Geerinckx-Rice <me@HIDDEN>, pelzflorian <pelzflorian@HIDDEN>,
 Christopher Baines <guix@HIDDEN>, Attila Lendvai <attila@HIDDEN>,
 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi Nigko,

Nigko Yerden <nigko.yerden@HIDDEN> skribis:

> Fix <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>
> 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 <https://issues.guix.gnu.org/72867>.
> +  (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 <https://issues.guix.gnu.org/72867>.
  (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)




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 26 Sep 2024 07:55:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Sep 26 03:55:20 2024
Received: from localhost ([127.0.0.1]:51761 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1stjLL-00031M-Df
	for submit <at> debbugs.gnu.org; Thu, 26 Sep 2024 03:55:20 -0400
Received: from mail-lf1-f65.google.com ([209.85.167.65]:57632)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1stijO-0008V9-L7
 for 72867 <at> debbugs.gnu.org; Thu, 26 Sep 2024 03:16:07 -0400
Received: by mail-lf1-f65.google.com with SMTP id
 2adb3069b0e04-536a2759f0eso1065933e87.3
 for <72867 <at> debbugs.gnu.org>; Thu, 26 Sep 2024 00:15:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1727334873; x=1727939673; darn=debbugs.gnu.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=sbYU6LGXkTuXePzvS5sp4/6XDPX7Jr04MLxw04ki7A8=;
 b=FaeOfyrL/G1JFh+iJUxi6Qwnqoy+DSS9AHYeH2vO3A01E3cZkFZAL34F57WAV3Rc8n
 dyy7zoMrqOlBC7iJ8uMz5icbxml6/F5lPdXdHi1C/Sa+fbdk9xM1Mm1kh+Kq/POv7yvp
 3OUPckLNx9CI0eqgzY1ER1ONd2zj6HvAJds42d/iq7PA1SOPDX9FBEdiWlUP9bbx2ReW
 vmEPQiqrzem1usjkcULLQUWMQp/T1qgigXG5G7+QIa8TXFSjUJW9z5eF2cldReu/VC8A
 OsN7KVj50BKH1VZMhj0UuoDp6UDhMNIjFft28rp9Uch41dHln7WTG7udKWqwOqw3w84U
 qlHw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1727334873; x=1727939673;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=sbYU6LGXkTuXePzvS5sp4/6XDPX7Jr04MLxw04ki7A8=;
 b=MDFYPND6M9dRVUzHC8pulmGHrR8j2NBUao8vZFYb7izUNOxZZc+Fy/qDc97LH8st9f
 tRCqCV+i3z3EWy5EUoFCIjsazcPyWd8qZuT0GfJPeaf3hbDY+n4kjWvoMor0G2qv/SbE
 8eGCkyflQ+oTWUs+6KMnYg6I412D7djng6iH9dT+/bfeGetqw8R4boSpE3JL6NvboOeq
 v4HtlFLR+tD0RE989oGsVWdbDjigiNqPIgEx4X0mqlhNc8J1Zg3l1S/lBraLiKxp3RXT
 pPpU80ZRJ+4nIplL9Dqn+jmq3vEkw/ruozDJ4uSdPi5YE98tPcg1WpLYho8AtGQ74Kx7
 a15Q==
X-Gm-Message-State: AOJu0YzjpAol6vwaETJe/i9qtawgDI/3j0+b5TO2YSTC6Rbf7wKEAfCV
 ui/mufIpTGzdBik3lYhzdSayNJqB9uskZncWdH1syxgRcs3kZAOjfwwa6afn
X-Google-Smtp-Source: AGHT+IFLPRwXqGASaPb3P7OPqw9PY7aUUMBxeTW1alJRW4Y09N8/UwcWQUK7jkRMFPRKZgX4bSKuNA==
X-Received: by 2002:a05:6512:39c7:b0:533:42ae:c985 with SMTP id
 2adb3069b0e04-5387753181dmr3597624e87.25.1727334872527; 
 Thu, 26 Sep 2024 00:14:32 -0700 (PDT)
Received: from localhost.localdomain ([188.168.141.132])
 by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-537a864d558sm718652e87.248.2024.09.26.00.14.31
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 26 Sep 2024 00:14:31 -0700 (PDT)
From: Nigko Yerden <nigko.yerden@HIDDEN>
To: 72867 <at> debbugs.gnu.org
Subject: [PATCH v6] gexp: Make 'local-file' follow symlinks.
Date: Thu, 26 Sep 2024 12:07:56 +0500
Message-ID: <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@HIDDEN>
X-Mailer: git-send-email 2.46.0
MIME-Version: 1.0
X-Debbugs-Cc: Christopher Baines <guix@HIDDEN>, Josselin Poiret <dev@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>, Simon Tournier <zimon.toutoune@HIDDEN>, Tobias Geerinckx-Rice <me@HIDDEN>
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Attila Lendvai <attila@HIDDEN>,
 pelzflorian <pelzflorian@HIDDEN>,
 Nigko Yerden <nigko.yerden@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Fix <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>
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
---
Hello all,

This version of patch advocated by Florian changes 'current-source-directory'
to always follow symlinks.

Regards,
Nigko

 guix/utils.scm |  8 ++------
 tests/gexp.scm | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/guix/utils.scm b/guix/utils.scm
index f161cb4ef3..d4591caced 100644
--- 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 relative and
-       ;; needs to be canonicalized.
-       (if (string-prefix? "/" file)
-           (dirname file)
-           (canonicalize-path (dirname file)))))))
+       (dirname (canonicalize-path file))))))
 
 (define-syntax current-source-directory
   (lambda (s)
@@ -1141,7 +1137,7 @@ (define-syntax current-source-directory
           ;; run time rather than expansion time is necessary to allow files
           ;; to be moved on the file system.
           (if (string-prefix? "/" file-name)
-              (dirname file-name)
+              (dirname (canonicalize-path file-name))
               #`(absolute-dirname #,file-name)))
          ((or ('filename . #f) #f)
           ;; raising an error would upset Geiser users
diff --git a/tests/gexp.scm b/tests/gexp.scm
index e066076c5c..cd502a1fb2 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -298,6 +298,39 @@ (define %extension-package
                  (equal? (scandir (string-append dir "/tests"))
                          '("." ".." "gexp.scm"))))))
 
+(test-assert "local-file, load through symlink"
+  ;; See <https://issues.guix.gnu.org/72867>.
+  (call-with-temporary-directory
+   (lambda (tmp-dir)
+     (chdir tmp-dir)
+     ;; create content file
+     (call-with-output-file "content"
+       (lambda (port) (display "Hi!" port)))
+     ;; Create module that call 'local-file'
+     ;; with the content file and returns its
+     ;; absolute file-name. An error is raised
+     ;; if the content 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")
+     (chdir "dir")
+     (symlink "../test-local-file.scm" "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 path. To test both
+     ;; of these branches we execute 'test-local-file.scm' symlink
+     ;; first as a module (corresponds to relative path):
+     (dynamic-wind
+       (lambda () (set! %load-path (cons "." %load-path)))
+       (lambda () (use-modules (test-local-file)))
+       (lambda () (set! %load-path (cdr %load-path))))
+     ;; and then as a regular code (corresponds to absolute path):
+     (load (string-append tmp-dir "/dir/test-local-file.scm")))))
+
 (test-assert "one plain file"
   (let* ((file     (plain-file "hi" "Hello, world!"))
          (exp      (gexp (display (ungexp file))))

base-commit: 404dbd894c69c94b483c6139d2a39b1c1eaddf36
-- 
2.46.0





Information forwarded to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 25 Sep 2024 05:17:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Sep 25 01:17:22 2024
Received: from localhost ([127.0.0.1]:42765 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1stKOv-0002KG-OQ
	for submit <at> debbugs.gnu.org; Wed, 25 Sep 2024 01:17:22 -0400
Received: from relay.yourmailgateway.de ([188.68.63.166]:35329)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1stKOs-0002K5-2K
 for 72867 <at> debbugs.gnu.org; Wed, 25 Sep 2024 01:17:19 -0400
Received: from mors-relay-8202.netcup.net (localhost [127.0.0.1])
 by mors-relay-8202.netcup.net (Postfix) with ESMTPS id 4XD4Vz6FcFz3tWf;
 Wed, 25 Sep 2024 07:08:11 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1727240891;
 bh=6XyflFZlmm4zDOqg1ojI0dqrSSK2/CNi9gl8kuXa+Fg=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=SRBnfuR+KNfOSOQz7eVMvSrQZbsDTCWW9JBMmrgM4DeYFWvrEmIXO0J+Of//rSJYH
 sJhfzIF8EK6JiEJYyLObIfbgGhnLWuP7cg4N99wsZRDt2/tnVFsRLNsU2jQsvYGsBk
 QWDUue1II19i/FFjB198sYAxxp2ahHX4vdUIc4+kHrezbuw237dioh0FQ8V476VZjR
 l9DLHBQVQvI9mHpnQBuRoJ2n6PGPZbWl4soQ1oRdf8LJiwVKCeERX8Qp/HMJh9aIhA
 qTl5aZK0Qfnh1o6+7PLNEeIOWirGKtsEfRpquaUWRx5I+CrVt2fwFtOuUSWhUyMEqA
 yKGOBXUiEILcQ==
Received: from policy01-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay-8202.netcup.net (Postfix) with ESMTPS id 4XD4Vz5XLkz3tPM;
 Wed, 25 Sep 2024 07:08:11 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at policy01-mors.netcup.net
X-Spam-Flag: NO
X-Spam-Score: -2.9
X-Spam-Level: 
X-Spam-Status: No, score=-2.9 required=6.31 tests=[ALL_TRUSTED=-1,
 BAYES_00=-1.9] autolearn=ham autolearn_force=no
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy01-mors.netcup.net (Postfix) with ESMTPS id 4XD4hy2LGMz8t43;
 Wed, 25 Sep 2024 07:16:49 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id 1437D83C3E;
 Wed, 25 Sep 2024 07:16:41 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
To: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: Re: [bug#72867] [PATCH v5] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <87r09vsyp1.fsf@HIDDEN> (pelzflorian@HIDDEN's
 message of "Sat, 07 Sep 2024 09:35:54 +0200")
References: <6e87ddd086b9188539eecfc83bdd6712aaf53a1a.1725596262.git.nigko.yerden@HIDDEN>
 <87r09vsyp1.fsf@HIDDEN>
Date: Wed, 25 Sep 2024 07:16:45 +0200
Message-ID: <87zfnws476.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="=-=-="
X-Rspamd-Queue-Id: 1437D83C3E
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: WlwxBALa+/YHptFhdod1O9RUObqzJTOGToB4t+rAUbPH9PHuMg8KvpRE
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Ludovic =?utf-8?Q?Court=C3=A8s?= <ludo@HIDDEN>,
 Tobias Geerinckx-Rice <me@HIDDEN>, 72867 <at> debbugs.gnu.org,
 Attila Lendvai <attila@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain

Hello Nigko.


--=-=-=
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline; filename=news
Content-Transfer-Encoding: quoted-printable

diff --git a/etc/news.scm b/etc/news.scm
index a90f92a9ff..5a32eee7f5 100644
--- a/etc/news.scm
+++ b/etc/news.scm
@@ -33,6 +33,18 @@
 (channel-news
  (version 0)
=20
+ (entry (commit "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
+        (title
+         (en "local-file behaves consistently for symlinks"))
+        (body
+         (en "Previous behavior differed between whether someone
+loaded the symlink or the actual scheme file.  One of them had to be
+broken, at least when loading a channel module.
+
+Affected users who expected paths relative to the symlink would need
+to append "/../.." or similar or the relative path to the =E2=80=9Creal=E2=
=80=9D file
+the symlink points to to the path.")))
+
  (entry (commit "2fae63df2138b74d30e120364f0f272871595862")
         (title
          (en "Core packages updated")

--=-=-=
Content-Type: text/plain



They would not have to write code like `current-source-directory'.

Also note that such affected users had broken code when running the
real file.

`local-file' with absolute paths always did `(canonicalize-path (dirname`
and does not change.
`dirname' being called in a special case of `current-source-directory',
`canonicalize-path' as part of `absolute-file-name'.

Could we finish this bug report by applying your nice test code, but
changing only `absolute-dirname' to do (canonicalize-path (dirname))
in all cases?

Then either add no news item, or write the above?

Regards,
Florian

--=-=-=--




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 7 Sep 2024 07:36:12 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Sep 07 03:36:12 2024
Received: from localhost ([127.0.0.1]:54703 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1smpzP-0001PV-JI
	for submit <at> debbugs.gnu.org; Sat, 07 Sep 2024 03:36:11 -0400
Received: from relay.yourmailgateway.de ([188.68.61.107]:34553)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1smpzK-0001PI-TM
 for 72867 <at> debbugs.gnu.org; Sat, 07 Sep 2024 03:36:10 -0400
Received: from mors-relay-8405.netcup.net (localhost [127.0.0.1])
 by mors-relay-8405.netcup.net (Postfix) with ESMTPS id 4X14dx18yLz6yWC;
 Sat,  7 Sep 2024 09:36:05 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1725694565;
 bh=tiBlDp80fjeJfboZuEyhS9KGw8pXQdwejKOXnE2IdWU=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=Usyy7UAbcsHhAw1yYsa+86wNk8SKEylZglt37Ouoyfq7xbx5Ge43pYU31P2OvWl3q
 f/JtTAOolAQsObX66EYOo3RxvGK7IvzGXr4gjr4cwfa+5SrPSjy4nIpwzTX3BbnSk1
 5zsbvBBrGT273/XiHfdIlBN5aRg4YXlRp+h40uQ2EfXnWkPe7fgGqj+NIkJa8ctK6e
 rjeCeh+DOP3pUgvlhKCq7Po4xWjkJ53KWiSH/rY3xuJJ9/pS59M9+6AYfVxKxsxSAk
 fI2BYk95Qw4VodMDB144h4hOjz6YwZ4hLRoV+a1PLrtb72c4RpF/gAKKfE2Pu/cpum
 XjHascekeeBLw==
Received: from policy02-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay-8405.netcup.net (Postfix) with ESMTPS id 4X14dx0T80z6yW6;
 Sat,  7 Sep 2024 09:36:05 +0200 (CEST)
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy02-mors.netcup.net (Postfix) with ESMTPS id 4X14dv4mH6z8svG;
 Sat,  7 Sep 2024 09:36:03 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id A43F084073;
 Sat,  7 Sep 2024 09:35:54 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
To: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: Re: [bug#72867] [PATCH v5] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <6e87ddd086b9188539eecfc83bdd6712aaf53a1a.1725596262.git.nigko.yerden@HIDDEN>
 (Nigko Yerden's message of "Fri, 6 Sep 2024 09:17:42 +0500")
References: <6e87ddd086b9188539eecfc83bdd6712aaf53a1a.1725596262.git.nigko.yerden@HIDDEN>
Date: Sat, 07 Sep 2024 09:35:54 +0200
Message-ID: <87r09vsyp1.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Rspamd-Queue-Id: A43F084073
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: Mun2qdbcfj1GO2pkVftdougG66gEfz2Cfp406hkkd+OZkfDPT0/9VP24
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Tobias Geerinckx-Rice <me@HIDDEN>,
 Ludovic =?utf-8?Q?Court=C3=A8s?= <ludo@HIDDEN>, 72867 <at> debbugs.gnu.org,
 Attila Lendvai <attila@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello Nigko, Tobias, Ludo, Attila (putting them in Cc again).

Nigko Yerden <nigko.yerden@HIDDEN> writes:
> Using of 'eval' in test from v4 is wrong. It does not play any role there.
> Most importantly it does not prevent spoiling of '%load-path' for the
> rest of 'tests/gexp.scm' module. Here is the better version of the test
> that uses 'dynamic-wind'.

The test is beautiful.  It makes clear why each
canonicalize-path is needed.  I had not understood the issue entirely
before I read it.

When we follow symlinks, both calling the real "../test-local-file.scm"
and the symlink to it behaves the same.

When not following symlinks, we get different results depending on what
we run.  I see no reason to ever want that except displaying info or
debugging.

And except that not following symlinks is faster (fewer stat syscalls).
But Ludovic wrapped absolute-dirname in a memoizing mlambda in commit
87b711d200ad13eaef284bdd1ab77f85618b0498, which reduces the difference.

Regarding the code, if we kept the old code when `follow-symlinks?' is
false (we should not, but if we did), it remains surprising that we do
follow some symlinks.

> +       (if follow-symlinks?
> +	   (dirname (canonicalize-path file))
> +	   ;; If there are relative names in %LOAD-PATH, FILE can be relative
> +	   ;; and needs to be canonicalized.
> +	   (if (string-prefix? "/" file)
> +               (dirname file)
> +               (canonicalize-path (dirname file))))))))

In the new use-modules part of the test, `file-name'
in `current-source-directory' is "./test-local-file.scm" code, which
means if we look at what happens if we not follow-symlinks, we took the
latter (canonicalize-path (dirname file)) path in
> (if (string-prefix? "/" file)
>        (dirname file)
>        (canonicalize-path (dirname file))))))))
which does not follow the symlink in the basename and fails.
But it would follow symlinks in the directory part.

Regards,
Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 6 Sep 2024 04:32:38 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Sep 06 00:32:38 2024
Received: from localhost ([127.0.0.1]:38763 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1smQeD-0004P8-N2
	for submit <at> debbugs.gnu.org; Fri, 06 Sep 2024 00:32:38 -0400
Received: from mail-lj1-f193.google.com ([209.85.208.193]:43424)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1smQeB-0004Ot-Cp
 for 72867 <at> debbugs.gnu.org; Fri, 06 Sep 2024 00:32:37 -0400
Received: by mail-lj1-f193.google.com with SMTP id
 38308e7fff4ca-2f6580c2bbfso22462771fa.1
 for <72867 <at> debbugs.gnu.org>; Thu, 05 Sep 2024 21:31:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725597022; x=1726201822; darn=debbugs.gnu.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=IkwfKRKfkhXXvd96s28C+sohNwKjTlOkT28L1F9j9iU=;
 b=YJzakMEsT2ewBqvKMxTaN3y7Ga3+gq7hagsC6Z7ad1mBHF/osb+PtcS8YmIFDx7hBW
 jSUVrYx79KkqQMVxddWbbBBi9gntlfkueyexayJeH4SDeWYSR6Qi/3+cfH1IiilNyQ81
 +JTrs/BapcK7CPSFq6AfgdqQHs5vAOvKuZsdAzjAZtO1xM585F4rqfUWe00Noqym0V2y
 yGzWh7zvNMah2+OPuJGl2XdepomMEXJiFc8HobqBG4ehgJv9DJTIslNercMzC2szf8YX
 lFu9zBeXeiFsb+qt/Y480emSUcVMVm+FGiQeO2s59dEySMjrDPkYGqViNV9sD62D21d1
 d5Og==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725597022; x=1726201822;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=IkwfKRKfkhXXvd96s28C+sohNwKjTlOkT28L1F9j9iU=;
 b=L5aBvI85I4YAslbm92AqMbc/dyGgZw/n48eKM0BLvpiRao/mONbBtcVqYrmtt32wNn
 NVEVw3xjJLznI725N9yjKFx8/O5P76CHy7V+9LD+oRN4FmJDAPmzIGRCu2Gtwuat9wEl
 NLLQB2XOGqJQKCcyVmixvRRb3QpSrktDESjMKIgH991ZL76PLnUhpr3JYdJN02Z9Gnk5
 VOSoZnHmlwOqSaxOjs58a+GBY1QbqFClVVUHMJP0/sO3yAIoHI/1QKLj7UWmDTcQPmxm
 q8OXM3vMw5ZcZsLU5zh9PNVW/2zLP31yZNI+mymDgkIMwPJRKiwjxw12Y4yq1isQ9x3f
 nv7w==
X-Gm-Message-State: AOJu0YwbE3DuetLv6HA1DOeqvpaLSExST/ekM33CLOlfBQYZhpxLiAKI
 G+Qf793oYtfZobTGJJKACYPLrn+cP9hq8f/XR9Lnx5l83+zDDhx8NXkaN/j5
X-Google-Smtp-Source: AGHT+IHbSLuPiVJmkvvXAJRhfkz93EizG3KhYD14x2zC+iTkzAGEIZrbvTgZkMQEzyUq2JO5J4075g==
X-Received: by 2002:a05:6512:2398:b0:533:1d4:546d with SMTP id
 2adb3069b0e04-5356776f777mr2541975e87.7.1725597021344; 
 Thu, 05 Sep 2024 21:30:21 -0700 (PDT)
Received: from localhost.localdomain ([188.168.141.132])
 by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-5356793daa9sm599247e87.56.2024.09.05.21.30.20
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Thu, 05 Sep 2024 21:30:21 -0700 (PDT)
From: Nigko Yerden <nigko.yerden@HIDDEN>
To: 72867 <at> debbugs.gnu.org
Subject: [PATCH v5] gexp: Make 'local-file' follow symlinks.
Date: Fri,  6 Sep 2024 09:17:42 +0500
Message-ID: <6e87ddd086b9188539eecfc83bdd6712aaf53a1a.1725596262.git.nigko.yerden@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Debbugs-Cc: Christopher Baines <guix@HIDDEN>, Josselin Poiret <dev@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>, Simon Tournier <zimon.toutoune@HIDDEN>, Tobias Geerinckx-Rice <me@HIDDEN>
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Florian Pelz <pelzflorian@HIDDEN>,
 Nigko Yerden <nigko.yerden@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Fixes <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>

While the issue can be easily fixed (a one line change in 'absolute-dirname')
by changing 'current-source-directory' so that it always follows symlinks,
such a change may break someone else's code. Instead, this patch keeps the
original behavior of 'current-source-directory' macro and adds optional
'follow-symlinks?' argument to it.

;;; Copyright © 2024 Nigko Yerden <nigko.yerden@HIDDEN>

* guix/utils.scm (absolute-dirname): Add 'follow-symlinks?' mandatory
argument.
(%guix-source-root-directory): Pass #f to 'absolute-dirname'
'follow-symlinks?' argument.
(current-source-directory): Add 'follow-symlinks?' optional argument.
* guix/gexp.scm (local-file): Pass #t to 'current-source-directory'
'follow-symlinks?' argument.
* tests/gexp.scm ("local-file, load through symlink"): New test.

Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59
---
Using of 'eval' in test from v4 is wrong. It does not play any role there.
Most importantly it does not prevent spoiling of '%load-path' for the
rest of 'tests/gexp.scm' module. Here is the better version of the test
that uses 'dynamic-wind'.

 guix/gexp.scm  |  2 +-
 guix/utils.scm | 53 ++++++++++++++++++++++++++++----------------------
 tests/gexp.scm | 33 +++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 24 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 74b4c49f90..5911ca4815 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -508,7 +508,7 @@ (define-syntax local-file
        (string? (syntax->datum #'file))
        ;; FILE is a literal, so resolve it relative to the source directory.
        #'(%local-file file
-                      (delay (absolute-file-name file (current-source-directory)))
+                      (delay (absolute-file-name file (current-source-directory #t)))
                       rest ...))
       ((_ (assume-valid-file-name file) rest ...)
        ;; FILE is not a literal, so resolve it relative to the current
diff --git a/guix/utils.scm b/guix/utils.scm
index d8ce6ed886..ea3d80707e 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1110,41 +1110,48 @@ (define (canonical-newline-port port)
 
 (define (%guix-source-root-directory)
   "Return the source root directory of the Guix found in %load-path."
-  (dirname (absolute-dirname "guix/packages.scm")))
+  (dirname (absolute-dirname "guix/packages.scm" #f)))
 
 (define absolute-dirname
   ;; Memoize to avoid repeated 'stat' storms from 'search-path'.
-  (mlambda (file)
+  (mlambda (file follow-symlinks?)
     "Return the absolute name of the directory containing FILE, or #f upon
-failure."
+failure. Follow symlinks if FOLLOW-SYMLINKS? is true."
     (match (search-path %load-path file)
       (#f #f)
       ((? string? file)
-       ;; If there are relative names in %LOAD-PATH, FILE can be relative and
-       ;; needs to be canonicalized.
-       (if (string-prefix? "/" file)
-           (dirname file)
-           (canonicalize-path (dirname file)))))))
+       (if follow-symlinks?
+	   (dirname (canonicalize-path file))
+	   ;; If there are relative names in %LOAD-PATH, FILE can be relative
+	   ;; and needs to be canonicalized.
+	   (if (string-prefix? "/" file)
+               (dirname file)
+               (canonicalize-path (dirname file))))))))
 
 (define-syntax current-source-directory
   (lambda (s)
     "Return the absolute name of the current directory, or #f if it could not
-be determined."
+be determined. Do not follow symlinks if FOLLOW-SYMLINKS? is false (the default)."
+    (define (source-directory follow-symlinks?)
+      (match (assq 'filename (or (syntax-source s) '()))
+	(('filename . (? string? file-name))
+	 ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
+	 ;; can be relative.  In that case, we try to find out at run time
+	 ;; the absolute file name by looking at %LOAD-PATH; doing this at
+	 ;; run time rather than expansion time is necessary to allow files
+	 ;; to be moved on the file system.
+	 (if (string-prefix? "/" file-name)
+	     (dirname (if follow-symlinks?
+			  (canonicalize-path file-name)
+			  file-name))
+	     #`(absolute-dirname #,file-name #,follow-symlinks?)))
+	((or ('filename . #f) #f)
+	 ;; raising an error would upset Geiser users
+	 #f)))
     (syntax-case s ()
-      ((_)
-       (match (assq 'filename (or (syntax-source s) '()))
-         (('filename . (? string? file-name))
-          ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
-          ;; can be relative.  In that case, we try to find out at run time
-          ;; the absolute file name by looking at %LOAD-PATH; doing this at
-          ;; run time rather than expansion time is necessary to allow files
-          ;; to be moved on the file system.
-          (if (string-prefix? "/" file-name)
-              (dirname file-name)
-              #`(absolute-dirname #,file-name)))
-         ((or ('filename . #f) #f)
-          ;; raising an error would upset Geiser users
-          #f))))))
+      ((_) (source-directory #f))
+      ((_ follow-symlinks?)
+       (source-directory (syntax->datum #'follow-symlinks?))))))
 
 
 ;;;
diff --git a/tests/gexp.scm b/tests/gexp.scm
index b35bfc920f..eec0f6e7ca 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -292,6 +292,39 @@ (define %extension-package
                  (equal? (scandir (string-append dir "/tests"))
                          '("." ".." "gexp.scm"))))))
 
+(test-assert "local-file, load through symlink"
+  ;; See <https://issues.guix.gnu.org/72867>.
+  (call-with-temporary-directory
+   (lambda (tmp-dir)
+     (chdir tmp-dir)
+     ;; create content file
+     (call-with-output-file "content"
+       (lambda (port) (display "Hi!" port)))
+     ;; Create module that call 'local-file'
+     ;; with the content file and returns its
+     ;; absolute file-name. An error is raised
+     ;; if the content 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")
+     (chdir "dir")
+     (symlink "../test-local-file.scm" "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 path. To test both
+     ;; of these branches we execute 'test-local-file.scm' symlink
+     ;; first as a module (corresponds to relative path):
+     (dynamic-wind
+       (lambda () (set! %load-path (cons "." %load-path)))
+       (lambda () (use-modules (test-local-file)))
+       (lambda () (set! %load-path (cdr %load-path))))
+     ;; and then as a regular code (corresponds to absolute path):
+     (load (string-append tmp-dir "/dir/test-local-file.scm")))))
+
 (test-assert "one plain file"
   (let* ((file     (plain-file "hi" "Hello, world!"))
          (exp      (gexp (display (ungexp file))))

base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a
-- 
2.45.2





Information forwarded to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 5 Sep 2024 05:08:36 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Sep 05 01:08:36 2024
Received: from localhost ([127.0.0.1]:35866 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sm4jU-0004RZ-IP
	for submit <at> debbugs.gnu.org; Thu, 05 Sep 2024 01:08:36 -0400
Received: from mail-lf1-f66.google.com ([209.85.167.66]:44153)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1sm4jS-0004RI-4u
 for 72867 <at> debbugs.gnu.org; Thu, 05 Sep 2024 01:08:34 -0400
Received: by mail-lf1-f66.google.com with SMTP id
 2adb3069b0e04-5353cd18c20so313542e87.0
 for <72867 <at> debbugs.gnu.org>; Wed, 04 Sep 2024 22:07:29 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725512783; x=1726117583; darn=debbugs.gnu.org;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:cc:to:subject:user-agent:mime-version:date:message-id
 :from:to:cc:subject:date:message-id:reply-to;
 bh=ce34yJ/GeyOWPsjIj8gvBRKBx47W33LU3d0Vj2VOa3A=;
 b=GZz4ssPfBVVFT+h/cv4Q9142iAqjIxkvAgBqsu2YZhT+cRhKhi2uIAGLYZD3M/5Rx5
 xKra4o/rM7IPPR8xlcEs1J5RAOA1uIIfFNp/rl17hFqYQ7sHeBvd+nuQkfIFTkxMMVf0
 blTxgKikE05+iDPiEhZqt1BAOu+NXoR11oKjr+5dAhyvfW/xixEgijJJi50OB3/ePYfE
 WkHKbMfpOAZGQ3eTrnXunVUK3oIUq+l2FE4nGiTCyc0uB9DQhUBTh3jdwCGX3dwf2sOm
 uTDouvUHMtLLROQ/O1SVfnL/TmV2Oqu4/K2Xp0tpsZ0zLGK46uCoRhabBpfYYpuRBHZV
 0hSw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725512783; x=1726117583;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:cc:to:subject:user-agent:mime-version:date:message-id
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=ce34yJ/GeyOWPsjIj8gvBRKBx47W33LU3d0Vj2VOa3A=;
 b=rH59c52x2EucIktt5hPl2hTlh+KAPVoecXncFJJnCLi7i97br5TiIfpYufDZLReHRh
 l/x8cg1DAQIPnMOIFHsed/cEQ+RYG7TITeLLhF0TYArXO1SU2FsQHmMT+D9MWEb0VLMt
 tnoY+am0AB5s8TKxj7kL2D5PG9YDXyxDhzuBjdVVrh2Wlue411awnlFU3q2xDACe7mIj
 cgXKZBfwRTg0WhMGTr/dmmEwUfJRW0+EpXbb8iBmejiHrhGUHY/O54Pk6Ofcw+NS/iUV
 vcLVkwJDAyGeESO9UKRwf97tKVcqZwIH5XZEZHnOXkFm7yM1Hl47ikQsVhUEkGhSjmf4
 6k5w==
X-Gm-Message-State: AOJu0Yw0Cw9OUCMgihfpT6V4XQfYbbXxHDNXheh0gGE8nQc3N68SkiH+
 YU6pYNhOQKCmdU13NYae0045At2ofORQt3LkGqfz7x+D8o3zVKnZYIhVc2w9
X-Google-Smtp-Source: AGHT+IGzoHW95/+SiHY/zcSoXhofFx8d8o8a7VInHEMRBbU0w5V4bR2iOXRT5ienmM8JKGuCAiXlsg==
X-Received: by 2002:a05:6512:2820:b0:52c:7fe3:d3e5 with SMTP id
 2adb3069b0e04-53565f55009mr3491552e87.50.1725512783031; 
 Wed, 04 Sep 2024 22:06:23 -0700 (PDT)
Received: from [127.0.0.1] ([188.168.141.132])
 by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-53653ad139fsm34147e87.155.2024.09.04.22.06.22
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Wed, 04 Sep 2024 22:06:22 -0700 (PDT)
Message-ID: <4be8c4ec-4cc5-4b2e-8485-940b8d0f17f2@HIDDEN>
Date: Thu, 5 Sep 2024 10:06:22 +0500
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [PATCH v3] gexp: Make 'local-file' follow symlinks.
To: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
References: <2d4b593eaea4fed1fb08031a599aaab032442041.1725263612.git.nigko.yerden@HIDDEN>
 <87zfoord4n.fsf@HIDDEN>
Content-Language: en-US
From: Nigko Yerden <nigko.yerden@HIDDEN>
In-Reply-To: <87zfoord4n.fsf@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello Florian,

pelzflorian (Florian Pelz) wrote:
> I also would favor to simplify `current-source-directory' and not add an
> optional follow-symlinks? argument.  I believe processing profiles is
> the only reasonable case that unconditionally following symlinks would
> break, and people do not do profile processing in outside code.
Why do you think that making 'current-source-directory' to always follow
symlinks would not break Guix's own code as well?

What are these people whose code would be broken supposed to do? I think
they would need to write their own 'current-source-directory' from scratch.
Why not help them by providing 'follow-symlinks?' argument?

Instead of 'current-source-directory' simplification we can also consider
changing the default for 'follow-symlinks?' to #t.

Regards,
Nigko




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 5 Sep 2024 04:25:18 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Sep 05 00:25:18 2024
Received: from localhost ([127.0.0.1]:35848 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sm43Z-00012k-FG
	for submit <at> debbugs.gnu.org; Thu, 05 Sep 2024 00:25:18 -0400
Received: from mail-lj1-f193.google.com ([209.85.208.193]:52425)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1sm3yB-0000cH-IQ
 for 72867 <at> debbugs.gnu.org; Thu, 05 Sep 2024 00:19:44 -0400
Received: by mail-lj1-f193.google.com with SMTP id
 38308e7fff4ca-2f4f24263acso6088721fa.0
 for <72867 <at> debbugs.gnu.org>; Wed, 04 Sep 2024 21:18:38 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725509852; x=1726114652; darn=debbugs.gnu.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=D+SGKjHxQ6C0TpGYX79nXcha7uotwQ3NJJOCxA/P2l4=;
 b=jvhoFGW4j1RyMTpB306twRTM/knt4GjNHtv3DXHs3evW/8/L1kk2BUbDjpYymj4IX1
 yDTwmHq4KdP3UJV9pemnKeUU4tX736IxPk60da+6qlpzu0iz55X2bfgIqcSYSClePwwK
 T2Ww/ai6oSbxxauSqsnekKB9gESDtkWYuTp7bC6lGG+Na9ku+RpjKdBmAGHYCBr/WTBC
 7P8cD9IkuMlCKbOQexbc7Maq5r9lZ5lhAyVnXF8zV1U59lOCXtrET/iC0endijHkRlut
 V/l5+4wC+rUCMyBv+1HwGWYyk1pbJGI5fow2C72s4dxA7j2iL7P7kiOP+vzCfWt11J0V
 qCDw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725509852; x=1726114652;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=D+SGKjHxQ6C0TpGYX79nXcha7uotwQ3NJJOCxA/P2l4=;
 b=ohYIx/ztr8YMWHBD9BF1J5waZxivDvvOgItdY2/Anz69QDMsLbl0CQsrzHa9rsFlTI
 9g0TayOjmKj9ddqH/1clZcCovqawQvAnR/J2EBrO5jkjBcxJo0jsFiCTKqrPXSmRU9I5
 JevL/uUNLSfEciy24zibXFnfzo07c6IHPbLiQBNOfAOG/vNSlPuZkC1DM2vGbgwhHw7f
 jQVA6KTvxYbC6kjWbqC6D6rwlP4D6emwFl9TRUO9bOoZLWYw3Xp9LMg/wZWZEM5jjZfe
 Vsbge9hTWcP6T4beO0kNP2o+88yjMJgqDPhg2FwhSwYjTEvqfOcATHe9ykDPHztzClYM
 H6Zg==
X-Gm-Message-State: AOJu0Ywig6P6BICEuKtPDeLbNBP91vf2P5fImY+4V1VvG8klGq3GkeAa
 jxY+wsmQIKTTaNpZwR09lnEtsdfWs06oGJ+jGFDQSgkZmMgGMDD4734YA3xM
X-Google-Smtp-Source: AGHT+IF1rEqKzxh9+dK00918pduC27f/FQNh9TQsoSsimsZHdAxdrRkiwoEhwVZeSB0bP2mWfXDIkA==
X-Received: by 2002:a2e:b8d6:0:b0:2ef:2ba5:d214 with SMTP id
 38308e7fff4ca-2f6105c4facmr222350691fa.4.1725509851120; 
 Wed, 04 Sep 2024 21:17:31 -0700 (PDT)
Received: from localhost.localdomain ([188.168.141.132])
 by smtp.gmail.com with ESMTPSA id
 38308e7fff4ca-2f74c785b1csm253941fa.136.2024.09.04.21.17.30
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 04 Sep 2024 21:17:30 -0700 (PDT)
From: Nigko Yerden <nigko.yerden@HIDDEN>
To: 72867 <at> debbugs.gnu.org
Subject: [PATCH v4] gexp: Make 'local-file' follow symlinks.
Date: Thu,  5 Sep 2024 09:16:51 +0500
Message-ID: <0676272a670d00cacf351da05bf909fec5435bea.1725509811.git.nigko.yerden@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Debbugs-Cc: Christopher Baines <guix@HIDDEN>, Josselin Poiret <dev@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>, Simon Tournier <zimon.toutoune@HIDDEN>, Tobias Geerinckx-Rice <me@HIDDEN>
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Florian Pelz <pelzflorian@HIDDEN>,
 Nigko Yerden <nigko.yerden@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Fixes <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>

While the issue can be easily fixed (a one line change in 'absolute-dirname')
by changing 'current-source-directory' so that it always follows symlinks,
such a change may break someone else's code. Instead, this patch keeps the
original behavior of 'current-source-directory' macro and adds optional
'follow-symlinks?' argument to it.

;;; Copyright © 2024 Nigko Yerden <nigko.yerden@HIDDEN>

* guix/utils.scm (absolute-dirname): Add 'follow-symlinks?' mandatory
argument.
(%guix-source-root-directory): Pass #f to 'absolute-dirname'
'follow-symlinks?' argument.
(current-source-directory): Add 'follow-symlinks?' optional argument.
* guix/gexp.scm (local-file): Pass #t to 'current-source-directory'
'follow-symlinks?' argument.
* tests/gexp.scm ("local-file, load through symlink"): New test.

Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59
---
Hello Florian,

pelzflorian (Florian Pelz) wrote:
>> * tests/gexp.scm ("local-file, load through symlink"): New test.
>
>This one is a good test; but it tests only half, namely the
>rare-in-practice case of `local-file' when loading a Scheme file.  Here,
>`current-source-directory' evaluate file-name to
>"/tmp/guix-directory.VxrxZT/dir/link-to-code.scm", which has a slash as
>prefix, so absolute-dirname is not called.

Thanks for noticing this. Indeed 'absolute-dirname' was not called.
I have fixed this by turning 'code.scm' into a module 'test-local-file.scm'
and loading it twice: first using 'use-module' and then via 'load'
(for some unclear reason 'primitive-load' causes an error here, so
I replaced it with 'load').


>Thanks for the credit, but it would be unusual to mention me in the
>commit message, where discussion does not count.

>Please do not put me in the commit message; I made no code contribution.

OK, I removed your name from the commit message.

Regards,
Nigko

 guix/gexp.scm  |  2 +-
 guix/utils.scm | 53 ++++++++++++++++++++++++++++----------------------
 tests/gexp.scm | 33 +++++++++++++++++++++++++++++++
 3 files changed, 64 insertions(+), 24 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 74b4c49f90..5911ca4815 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -508,7 +508,7 @@ (define-syntax local-file
        (string? (syntax->datum #'file))
        ;; FILE is a literal, so resolve it relative to the source directory.
        #'(%local-file file
-                      (delay (absolute-file-name file (current-source-directory)))
+                      (delay (absolute-file-name file (current-source-directory #t)))
                       rest ...))
       ((_ (assume-valid-file-name file) rest ...)
        ;; FILE is not a literal, so resolve it relative to the current
diff --git a/guix/utils.scm b/guix/utils.scm
index d8ce6ed886..ea3d80707e 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1110,41 +1110,48 @@ (define (canonical-newline-port port)
 
 (define (%guix-source-root-directory)
   "Return the source root directory of the Guix found in %load-path."
-  (dirname (absolute-dirname "guix/packages.scm")))
+  (dirname (absolute-dirname "guix/packages.scm" #f)))
 
 (define absolute-dirname
   ;; Memoize to avoid repeated 'stat' storms from 'search-path'.
-  (mlambda (file)
+  (mlambda (file follow-symlinks?)
     "Return the absolute name of the directory containing FILE, or #f upon
-failure."
+failure. Follow symlinks if FOLLOW-SYMLINKS? is true."
     (match (search-path %load-path file)
       (#f #f)
       ((? string? file)
-       ;; If there are relative names in %LOAD-PATH, FILE can be relative and
-       ;; needs to be canonicalized.
-       (if (string-prefix? "/" file)
-           (dirname file)
-           (canonicalize-path (dirname file)))))))
+       (if follow-symlinks?
+	   (dirname (canonicalize-path file))
+	   ;; If there are relative names in %LOAD-PATH, FILE can be relative
+	   ;; and needs to be canonicalized.
+	   (if (string-prefix? "/" file)
+               (dirname file)
+               (canonicalize-path (dirname file))))))))
 
 (define-syntax current-source-directory
   (lambda (s)
     "Return the absolute name of the current directory, or #f if it could not
-be determined."
+be determined. Do not follow symlinks if FOLLOW-SYMLINKS? is false (the default)."
+    (define (source-directory follow-symlinks?)
+      (match (assq 'filename (or (syntax-source s) '()))
+	(('filename . (? string? file-name))
+	 ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
+	 ;; can be relative.  In that case, we try to find out at run time
+	 ;; the absolute file name by looking at %LOAD-PATH; doing this at
+	 ;; run time rather than expansion time is necessary to allow files
+	 ;; to be moved on the file system.
+	 (if (string-prefix? "/" file-name)
+	     (dirname (if follow-symlinks?
+			  (canonicalize-path file-name)
+			  file-name))
+	     #`(absolute-dirname #,file-name #,follow-symlinks?)))
+	((or ('filename . #f) #f)
+	 ;; raising an error would upset Geiser users
+	 #f)))
     (syntax-case s ()
-      ((_)
-       (match (assq 'filename (or (syntax-source s) '()))
-         (('filename . (? string? file-name))
-          ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
-          ;; can be relative.  In that case, we try to find out at run time
-          ;; the absolute file name by looking at %LOAD-PATH; doing this at
-          ;; run time rather than expansion time is necessary to allow files
-          ;; to be moved on the file system.
-          (if (string-prefix? "/" file-name)
-              (dirname file-name)
-              #`(absolute-dirname #,file-name)))
-         ((or ('filename . #f) #f)
-          ;; raising an error would upset Geiser users
-          #f))))))
+      ((_) (source-directory #f))
+      ((_ follow-symlinks?)
+       (source-directory (syntax->datum #'follow-symlinks?))))))
 
 
 ;;;
diff --git a/tests/gexp.scm b/tests/gexp.scm
index b35bfc920f..8f267214cd 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -292,6 +292,39 @@ (define %extension-package
                  (equal? (scandir (string-append dir "/tests"))
                          '("." ".." "gexp.scm"))))))
 
+(test-assert "local-file, load through symlink"
+  ;; See <https://issues.guix.gnu.org/72867>.
+  (call-with-temporary-directory
+   (lambda (tmp-dir)
+     (chdir tmp-dir)
+     ;; create content file
+     (call-with-output-file "content"
+       (lambda (port) (display "Hi!" port)))
+     ;; Create module that call 'local-file'
+     ;; with the content file and returns its
+     ;; absolute file-name. An error is raised
+     ;; if the content 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")
+     (chdir "dir")
+     (symlink "../test-local-file.scm" "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 path. To test both
+     ;; of these branches we execute 'test-local-file.scm' symlink 
+     ;; first as a module (corresponds to relative path):
+     (eval (begin
+             (add-to-load-path ".")
+             (use-modules (test-local-file)))
+           (current-module))
+     ;; and then as a regular code (corresponds to absolute path):
+     (load (string-append tmp-dir "/dir/test-local-file.scm")))))
+
 (test-assert "one plain file"
   (let* ((file     (plain-file "hi" "Hello, world!"))
          (exp      (gexp (display (ungexp file))))

base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a
-- 
2.45.2





Information forwarded to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 3 Sep 2024 15:06:59 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Tue Sep 03 11:06:59 2024
Received: from localhost ([127.0.0.1]:60532 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1slV7T-00078T-Fu
	for submit <at> debbugs.gnu.org; Tue, 03 Sep 2024 11:06:59 -0400
Received: from relay.yourmailgateway.de ([188.68.63.170]:50211)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1slV7P-00078I-RL
 for 72867 <at> debbugs.gnu.org; Tue, 03 Sep 2024 11:06:57 -0400
Received: from mors-relay8203.netcup.net (localhost [127.0.0.1])
 by mors-relay8203.netcup.net (Postfix) with ESMTPS id 4Wyppl4HVPz8Zmm;
 Tue,  3 Sep 2024 15:05:51 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1725375951;
 bh=84dsk/8IidU9RSSF6xxOWRqHJc8B8v2Ko5JD6S7p9bo=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=apw1ss2oX43cyQyL87QSXVBVbJAVunlgvSUwK0OYEpiKujgaSzbh/HjpGtbeWOyMs
 /dgZ+5t75UMM9Zgb7HnKgdntHtCKMp9I+11r4AtOnqJErY7sVUldyWuJXjqjIBT0mC
 ZEQMYxSaof5qAstNaotFJMgWuIeG2qB5AET3+ACHvP1R9XHQYNc5HK2Y1Kf4pjDUIK
 bYHGmtehktNd7CBoJGyZ57XDd2HHfBjbKThLZFIIYM/ThFNwIksBId3qmu/bP4OTMi
 I+FnFglfIrBkcGUOvDldF9oF3m+ijmYcxJHfxecTzY1MiGbuaNZLWUjY68xZ/AuIQK
 GZrDe2NAX+SQQ==
Received: from policy01-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay8203.netcup.net (Postfix) with ESMTPS id 4Wyppl3Zq3z8ZmB;
 Tue,  3 Sep 2024 15:05:51 +0000 (UTC)
X-Virus-Scanned: Debian amavisd-new at policy01-mors.netcup.net
X-Spam-Flag: NO
X-Spam-Score: -2.897
X-Spam-Level: 
X-Spam-Status: No, score=-2.897 required=6.31 tests=[ALL_TRUSTED=-1,
 BAYES_00=-1.9, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001,
 URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy01-mors.netcup.net (Postfix) with ESMTPS id 4Wyppl00tfz8scP;
 Tue,  3 Sep 2024 17:05:50 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id 536FD83F42;
 Tue,  3 Sep 2024 17:05:44 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
To: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: Re: [PATCH v3] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <2d4b593eaea4fed1fb08031a599aaab032442041.1725263612.git.nigko.yerden@HIDDEN>
 (Nigko Yerden's message of "Mon, 2 Sep 2024 12:53:32 +0500")
References: <2d4b593eaea4fed1fb08031a599aaab032442041.1725263612.git.nigko.yerden@HIDDEN>
Date: Tue, 03 Sep 2024 17:05:44 +0200
Message-ID: <87zfoord4n.fsf@HIDDEN>
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-Rspamd-Queue-Id: 536FD83F42
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: cBUpGpW9i2cOUM2Ogld/M59O4a7S4TXpbkhI7gBSO1trr1sNgFxDL01P
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello Nigko.

Nigko Yerden <nigko.yerden@HIDDEN> writes:
> This patch is the result of collective work of
> Florian Pelz <pelzflorian@HIDDEN> and
> Nigko Yerden <nigko.yerden@HIDDEN>

Thanks for the credit, but it would be unusual to mention me in the
commit message, where discussion does not count.

Please do not put me in the commit message; I made no code contribution.

I also would favor to simplify `current-source-directory' and not add an
optional follow-symlinks? argument.  I believe processing profiles is
the only reasonable case that unconditionally following symlinks would
break, and people do not do profile processing in outside code.

> * tests/gexp.scm ("local-file, load through symlink"): New test.

This one is a good test; but it tests only half, namely the
rare-in-practice case of `local-file' when loading a Scheme file.  Here,
`current-source-directory' evaluate file-name to
"/tmp/guix-directory.VxrxZT/dir/link-to-code.scm", which has a slash as
prefix, so absolute-dirname is not called.

The original issue is that the package in a channel according to
cookbook=E2=80=99s =E2=80=9CThe Repository as a Channel=E2=80=9D cannot be =
built when the
load-path is set up in the usual way.  There, absolute-dirname gets
called.  I think we would need a (very similar) test that covers this.

Instead of primitive-load, we would need to invoke Guile on a file in a
channel or in the GUILE_LOAD_PATH, or set %load-path.  I may be wrong
here and do not know how, but we definitely should cover when
`file-name' in is not prefixed with a slash.

Regards,
Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 2 Sep 2024 08:05:14 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Sep 02 04:05:14 2024
Received: from localhost ([127.0.0.1]:43619 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sl23m-0005Ru-7g
	for submit <at> debbugs.gnu.org; Mon, 02 Sep 2024 04:05:14 -0400
Received: from mail-ed1-f66.google.com ([209.85.208.66]:61487)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1sl23k-0005Rb-FK
 for 72867 <at> debbugs.gnu.org; Mon, 02 Sep 2024 04:05:13 -0400
Received: by mail-ed1-f66.google.com with SMTP id
 4fb4d7f45d1cf-5c24c92f699so1482584a12.2
 for <72867 <at> debbugs.gnu.org>; Mon, 02 Sep 2024 01:04:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725264185; x=1725868985; darn=debbugs.gnu.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=ao860WMWNrVRDzs/GEQFsN8DTsCi/x7LOg2QxgAv34M=;
 b=PF76Bl84BS/xzj4ckQsFyi69PBZGj6m7bBwF7ZCI9JpQQOtCBXji24CGOjP7OOKbSr
 Ba3OhvBGwOeg3Ua3OVgQxxIcTvIz+6yaz18d+SNJ89SAQ/9l+WKt1J2BO40B75L96kRT
 NfpjlxcUD6OXwSef5K72Ix6sNOVRnjTitrCrJFiKR+JrlGysKxjkaop5nDkMbW6AUQtW
 z0EdeqhQr92oTTR2J5AynXonr/LWYpF1dkTJTtjgIogYEEiVkZKvjQRtEcBXl++3iotO
 NPpt9wO2kUfEylzSXA0Ad+2dQXbCFnGPD4A9KjPgoPGrDf14EPDBye57RYtl9ARLCHww
 UFxQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725264185; x=1725868985;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=ao860WMWNrVRDzs/GEQFsN8DTsCi/x7LOg2QxgAv34M=;
 b=QXSP9oK5mjyI3zhZ/TqphjP8+w/Aphu6qkJ5IVy//Gu0bKlCXg67ZPcFWtT6EBmWdX
 4IVplR7/RfhVb1oTbwSlFCfH1EgKy0Fa2FBlBginSBurp8C5X8oPt11ipWTKzfijCINX
 tMIV0PRRZkx/qm/4wFT9KdRQcopZZ1/GzRTuSIqXK4KBAJqZpAPMP8mpPkeyL0tw2Rgb
 tUpYM8UXH1c8+0ne8YGO6dvhKX8TTbqzrO4VXu5pGHxT3VqBipNiBotubxSFtWuN8OUF
 ODd4VRmNIRjoDblHLoNL9VmU0Uv7SveikGa99OYtinySFPgfZUuUU2Pj1IPquZlblp2p
 /4jw==
X-Gm-Message-State: AOJu0YxXApWFFLdnsVxQNGvEKWtdWNMn7npOtL17/Ve403YoHmboXR7p
 623nqkh4N0BxtzUr6doMJ0zFEuU26DJr4S6jIKK9xU6Aj94xZcxIYshOE9yu
X-Google-Smtp-Source: AGHT+IGrt++f3j5Ia5OBtlBMSP1+FozFwD/+zpqLYwLAtuWboPQ+2zKO7do7tlOAvbK4/YTYJhQUXA==
X-Received: by 2002:a05:6512:3e26:b0:533:43bf:565d with SMTP id
 2adb3069b0e04-53546b45292mr6688625e87.27.1725263817977; 
 Mon, 02 Sep 2024 00:56:57 -0700 (PDT)
Received: from localhost.localdomain ([188.68.137.106])
 by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-5354084b61fsm1526326e87.239.2024.09.02.00.56.57
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Mon, 02 Sep 2024 00:56:57 -0700 (PDT)
From: Nigko Yerden <nigko.yerden@HIDDEN>
To: 72867 <at> debbugs.gnu.org
Subject: [PATCH v3] gexp: Make 'local-file' follow symlinks.
Date: Mon,  2 Sep 2024 12:53:32 +0500
Message-ID: <2d4b593eaea4fed1fb08031a599aaab032442041.1725263612.git.nigko.yerden@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
X-Debbugs-Cc: Christopher Baines <guix@HIDDEN>, Josselin Poiret <dev@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>, Simon Tournier <zimon.toutoune@HIDDEN>, Tobias Geerinckx-Rice <me@HIDDEN>
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: pelzflorian@HIDDEN, Nigko Yerden <nigko.yerden@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Fixes <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>

While the issue can be easily fixed (a one line change in 'absolute-dirname')
by changing 'current-source-directory' so that it always follows symlinks,
such a change may break someone else's code. Instead, this patch keeps the
original behavior of 'current-source-directory' macro and adds optional
'follow-symlinks?' argument to it.

This patch is the result of collective work of
Florian Pelz <pelzflorian@HIDDEN> and
Nigko Yerden <nigko.yerden@HIDDEN>

* guix/utils.scm (absolute-dirname): Add 'follow-symlinks?' mandatory
argument.
(%guix-source-root-directory): Pass #f to 'absolute-dirname'
'follow-symlinks?' argument.
(current-source-directory): Add 'follow-symlinks?' optional argument.
* guix/gexp.scm (local-file): Pass #t to 'current-source-directory'
'follow-symlinks?' argument.
* tests/gexp.scm ("local-file, load through symlink"): New test.

Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59
---
Forgot to unwrap #'follow-symlinks? syntax object with 'syntax->datum'
when calling 'source-directory' inside 'current-source-directory'.

 guix/gexp.scm  |  2 +-
 guix/utils.scm | 53 ++++++++++++++++++++++++++++----------------------
 tests/gexp.scm | 23 ++++++++++++++++++++++
 3 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 74b4c49f90..5911ca4815 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -508,7 +508,7 @@ (define-syntax local-file
        (string? (syntax->datum #'file))
        ;; FILE is a literal, so resolve it relative to the source directory.
        #'(%local-file file
-                      (delay (absolute-file-name file (current-source-directory)))
+                      (delay (absolute-file-name file (current-source-directory #t)))
                       rest ...))
       ((_ (assume-valid-file-name file) rest ...)
        ;; FILE is not a literal, so resolve it relative to the current
diff --git a/guix/utils.scm b/guix/utils.scm
index d8ce6ed886..ea3d80707e 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1110,41 +1110,48 @@ (define (canonical-newline-port port)
 
 (define (%guix-source-root-directory)
   "Return the source root directory of the Guix found in %load-path."
-  (dirname (absolute-dirname "guix/packages.scm")))
+  (dirname (absolute-dirname "guix/packages.scm" #f)))
 
 (define absolute-dirname
   ;; Memoize to avoid repeated 'stat' storms from 'search-path'.
-  (mlambda (file)
+  (mlambda (file follow-symlinks?)
     "Return the absolute name of the directory containing FILE, or #f upon
-failure."
+failure. Follow symlinks if FOLLOW-SYMLINKS? is true."
     (match (search-path %load-path file)
       (#f #f)
       ((? string? file)
-       ;; If there are relative names in %LOAD-PATH, FILE can be relative and
-       ;; needs to be canonicalized.
-       (if (string-prefix? "/" file)
-           (dirname file)
-           (canonicalize-path (dirname file)))))))
+       (if follow-symlinks?
+	   (dirname (canonicalize-path file))
+	   ;; If there are relative names in %LOAD-PATH, FILE can be relative
+	   ;; and needs to be canonicalized.
+	   (if (string-prefix? "/" file)
+               (dirname file)
+               (canonicalize-path (dirname file))))))))
 
 (define-syntax current-source-directory
   (lambda (s)
     "Return the absolute name of the current directory, or #f if it could not
-be determined."
+be determined. Do not follow symlinks if FOLLOW-SYMLINKS? is false (the default)."
+    (define (source-directory follow-symlinks?)
+      (match (assq 'filename (or (syntax-source s) '()))
+	(('filename . (? string? file-name))
+	 ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
+	 ;; can be relative.  In that case, we try to find out at run time
+	 ;; the absolute file name by looking at %LOAD-PATH; doing this at
+	 ;; run time rather than expansion time is necessary to allow files
+	 ;; to be moved on the file system.
+	 (if (string-prefix? "/" file-name)
+	     (dirname (if follow-symlinks?
+			  (canonicalize-path file-name)
+			  file-name))
+	     #`(absolute-dirname #,file-name #,follow-symlinks?)))
+	((or ('filename . #f) #f)
+	 ;; raising an error would upset Geiser users
+	 #f)))
     (syntax-case s ()
-      ((_)
-       (match (assq 'filename (or (syntax-source s) '()))
-         (('filename . (? string? file-name))
-          ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
-          ;; can be relative.  In that case, we try to find out at run time
-          ;; the absolute file name by looking at %LOAD-PATH; doing this at
-          ;; run time rather than expansion time is necessary to allow files
-          ;; to be moved on the file system.
-          (if (string-prefix? "/" file-name)
-              (dirname file-name)
-              #`(absolute-dirname #,file-name)))
-         ((or ('filename . #f) #f)
-          ;; raising an error would upset Geiser users
-          #f))))))
+      ((_) (source-directory #f))
+      ((_ follow-symlinks?)
+       (source-directory (syntax->datum #'follow-symlinks?))))))
 
 
 ;;;
diff --git a/tests/gexp.scm b/tests/gexp.scm
index b35bfc920f..843037fa84 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -292,6 +292,29 @@ (define %extension-package
                  (equal? (scandir (string-append dir "/tests"))
                          '("." ".." "gexp.scm"))))))
 
+(test-assert "local-file, load through symlink"
+  ;; See <https://issues.guix.gnu.org/72867>.
+  (call-with-temporary-directory
+   (lambda (tmp-dir)
+     (chdir tmp-dir)
+     ;; create content file
+     (call-with-output-file "content"
+       (lambda (port) (display "Hi!" port)))
+     ;; create code that call 'local-file'
+     ;; with the content file and returns its
+     ;; absolute file-name. An error is raised
+     ;; if the content file can't be found.
+     (call-with-output-file "code.scm"
+       (lambda (port) (display "\
+(use-modules (guix gexp))
+(define file (local-file \"content\" \"test-file\"))
+(local-file-absolute-file-name file)" port)))
+     (mkdir "dir")
+     (chdir "dir")
+     (symlink "../code.scm" "link-to-code.scm")
+     ;; call 'local-file' through symlink
+     (primitive-load (string-append tmp-dir "/dir/link-to-code.scm")))))
+
 (test-assert "one plain file"
   (let* ((file     (plain-file "hi" "Hello, world!"))
          (exp      (gexp (display (ungexp file))))

base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a
-- 
2.45.2





Information forwarded to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 2 Sep 2024 05:25:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Sep 02 01:25:16 2024
Received: from localhost ([127.0.0.1]:43100 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1skzYx-0005d6-Rf
	for submit <at> debbugs.gnu.org; Mon, 02 Sep 2024 01:25:16 -0400
Received: from mail-lj1-f196.google.com ([209.85.208.196]:51495)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1skyy6-0003ZO-Sd
 for 72867 <at> debbugs.gnu.org; Mon, 02 Sep 2024 00:47:11 -0400
Received: by mail-lj1-f196.google.com with SMTP id
 38308e7fff4ca-2f50966c469so42150111fa.3
 for <72867 <at> debbugs.gnu.org>; Sun, 01 Sep 2024 21:46:10 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725252303; x=1725857103; darn=debbugs.gnu.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=zejtdo0J87SFBzYbjXQy5nY9TsabxKK2J2c9hZ/a8Ss=;
 b=VWNMDzuUoWIRRmgevL9084vA2m2do/KpMvqahkY6CylKUWgoQIcmdCa5YwXjZTqbbo
 FsfjaIEpNqAMMMOje1uK3vocaaKTsVpGL/sOMiQsQNU0m8/YPa++oCXoMHLXLEv1XARP
 jTsl3mMnITg+nzcomJbLUvT79ZOhknC9lSt0RJWwKaO7CJnWHDs3bxMnhQRrr+SBzHDo
 +SHqaLpcWhvj3hbErHDHnljEFDi0BDyWZCjdnz7QHWb9k04BJHtBwoGhzU4CIA2kebrs
 81WRTpZEbAzo1UmqggrXHWDSpeIdPmgpBLFiUkW7BHXdrTQrfqNLwxl/4Et2jw0OFzkF
 JKQg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725252303; x=1725857103;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=zejtdo0J87SFBzYbjXQy5nY9TsabxKK2J2c9hZ/a8Ss=;
 b=Sgu3MXXZjOGoyHxMObqt4mvVTX4WD3M8C60JcaLvUZy/Xd8ZuDNAvo/ahtVrH340iR
 ETcxXlZAYlttwZvnfaHe1BtYcB+dSTd2YbApiJUWSMM8pWZywukRN4teydUr52Zq/B6Z
 hd4hYJMmA6babUk0iCaVoWl9nMLm/Y+ehcC41z3/GcBLxEQ8e/YPnHi8uyvPSau+3Y2L
 lJvTkWVKWfzPIdEasxSO0UbaqRlJxtECShZwNHW6E2xAw9mMLeCpGiI5jXvw8ND+SpKq
 i5sShOXLtDgif76p7nh03eO+WeEZdxkWe9+AfoQUDexn7CJBgSkZKgvNh+zwfhef7Nvz
 J1Jg==
X-Gm-Message-State: AOJu0Yznx9EACVrn4q3GoRPwgQLSFEXcGejrBHEMW2vRgHeMvH5ZgpE9
 i5tfsQJHDsXFWludh/R1/TbOfV1V9G7Q3B8WcQPQpDo61B16kS/Vlkks+EB4
X-Google-Smtp-Source: AGHT+IFU2tt/wevjZbrLOsnDGi1MgSksByyxKIf/2zqKA0R7Y4eHnOLnaEt+bRV2eKgbIHOheF/G7w==
X-Received: by 2002:a05:6512:6cc:b0:530:ae4f:337a with SMTP id
 2adb3069b0e04-53546afaddamr6289499e87.3.1725252302422; 
 Sun, 01 Sep 2024 21:45:02 -0700 (PDT)
Received: from localhost.localdomain ([188.68.137.106])
 by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-535407b8727sm1452656e87.119.2024.09.01.21.45.01
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Sun, 01 Sep 2024 21:45:02 -0700 (PDT)
From: Nigko Yerden <nigko.yerden@HIDDEN>
To: 72867 <at> debbugs.gnu.org
Subject: [PATCH v2] gexp: Make 'local-file' follow symlinks.
Date: Mon,  2 Sep 2024 09:41:59 +0500
Message-ID: <e857ab34801ae7d1270eff9fe8b6376d039af5d6.1725252117.git.nigko.yerden@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
X-Debbugs-Cc: Christopher Baines <guix@HIDDEN>, Josselin Poiret <dev@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>, Simon Tournier <zimon.toutoune@HIDDEN>, Tobias Geerinckx-Rice <me@HIDDEN>
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: pelzflorian@HIDDEN, Nigko Yerden <nigko.yerden@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Fixes <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>

While the issue can be easily fixed (a one line change in 'absolute-dirname')
by changing 'current-source-directory' so that it always follows symlinks,
such a change may break someone else's code. Instead, this patch keeps the
original behavior of 'current-source-directory' macro and adds optional
'follow-symlinks?' argument to it.

This patch is the result of collective work of
Florian Pelz <pelzflorian@HIDDEN> and
Nigko Yerden <nigko.yerden@HIDDEN>

* guix/utils.scm (absolute-dirname): Add 'follow-symlinks?' mandatory
argument.
(%guix-source-root-directory): Pass #f to 'absolute-dirname'
'follow-symlinks?' argument.
(current-source-directory): Add 'follow-symlinks?' optional argument.
* guix/gexp.scm (local-file): Pass #t to 'current-source-directory'
'follow-symlinks?' argument.
* tests/gexp.scm ("local-file, load through symlink"): New test.

Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59
---
Hello Ludo, Florian,

Add test to 'local-file'.

Regards,
Nigko

 guix/gexp.scm  |  2 +-
 guix/utils.scm | 52 ++++++++++++++++++++++++++++----------------------
 tests/gexp.scm | 23 ++++++++++++++++++++++
 3 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 74b4c49f90..5911ca4815 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -508,7 +508,7 @@ (define-syntax local-file
        (string? (syntax->datum #'file))
        ;; FILE is a literal, so resolve it relative to the source directory.
        #'(%local-file file
-                      (delay (absolute-file-name file (current-source-directory)))
+                      (delay (absolute-file-name file (current-source-directory #t)))
                       rest ...))
       ((_ (assume-valid-file-name file) rest ...)
        ;; FILE is not a literal, so resolve it relative to the current
diff --git a/guix/utils.scm b/guix/utils.scm
index d8ce6ed886..b5fcf8cb28 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1110,41 +1110,47 @@ (define (canonical-newline-port port)
 
 (define (%guix-source-root-directory)
   "Return the source root directory of the Guix found in %load-path."
-  (dirname (absolute-dirname "guix/packages.scm")))
+  (dirname (absolute-dirname "guix/packages.scm" #f)))
 
 (define absolute-dirname
   ;; Memoize to avoid repeated 'stat' storms from 'search-path'.
-  (mlambda (file)
+  (mlambda (file follow-symlinks?)
     "Return the absolute name of the directory containing FILE, or #f upon
-failure."
+failure. Follow symlinks if FOLLOW-SYMLINKS? is true."
     (match (search-path %load-path file)
       (#f #f)
       ((? string? file)
-       ;; If there are relative names in %LOAD-PATH, FILE can be relative and
-       ;; needs to be canonicalized.
-       (if (string-prefix? "/" file)
-           (dirname file)
-           (canonicalize-path (dirname file)))))))
+       (if follow-symlinks?
+	   (dirname (canonicalize-path file))
+	   ;; If there are relative names in %LOAD-PATH, FILE can be relative
+	   ;; and needs to be canonicalized.
+	   (if (string-prefix? "/" file)
+               (dirname file)
+               (canonicalize-path (dirname file))))))))
 
 (define-syntax current-source-directory
   (lambda (s)
     "Return the absolute name of the current directory, or #f if it could not
-be determined."
+be determined. Do not follow symlinks if FOLLOW-SYMLINKS? is false (the default)."
+    (define (source-directory follow-symlinks?)
+      (match (assq 'filename (or (syntax-source s) '()))
+	(('filename . (? string? file-name))
+	 ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
+	 ;; can be relative.  In that case, we try to find out at run time
+	 ;; the absolute file name by looking at %LOAD-PATH; doing this at
+	 ;; run time rather than expansion time is necessary to allow files
+	 ;; to be moved on the file system.
+	 (if (string-prefix? "/" file-name)
+	     (dirname (if follow-symlinks?
+			  (canonicalize-path file-name)
+			  file-name))
+	     #`(absolute-dirname #,file-name #,follow-symlinks?)))
+	((or ('filename . #f) #f)
+	 ;; raising an error would upset Geiser users
+	 #f)))
     (syntax-case s ()
-      ((_)
-       (match (assq 'filename (or (syntax-source s) '()))
-         (('filename . (? string? file-name))
-          ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
-          ;; can be relative.  In that case, we try to find out at run time
-          ;; the absolute file name by looking at %LOAD-PATH; doing this at
-          ;; run time rather than expansion time is necessary to allow files
-          ;; to be moved on the file system.
-          (if (string-prefix? "/" file-name)
-              (dirname file-name)
-              #`(absolute-dirname #,file-name)))
-         ((or ('filename . #f) #f)
-          ;; raising an error would upset Geiser users
-          #f))))))
+      ((_) (source-directory #f))
+      ((_ follow-symlinks?) (source-directory #'follow-symlinks?)))))
 
 
 ;;;
diff --git a/tests/gexp.scm b/tests/gexp.scm
index b35bfc920f..843037fa84 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -292,6 +292,29 @@ (define %extension-package
                  (equal? (scandir (string-append dir "/tests"))
                          '("." ".." "gexp.scm"))))))
 
+(test-assert "local-file, load through symlink"
+  ;; See <https://issues.guix.gnu.org/72867>.
+  (call-with-temporary-directory
+   (lambda (tmp-dir)
+     (chdir tmp-dir)
+     ;; create content file
+     (call-with-output-file "content"
+       (lambda (port) (display "Hi!" port)))
+     ;; create code that call 'local-file'
+     ;; with the content file and returns its
+     ;; absolute file-name. An error is raised
+     ;; if the content file can't be found.
+     (call-with-output-file "code.scm"
+       (lambda (port) (display "\
+(use-modules (guix gexp))
+(define file (local-file \"content\" \"test-file\"))
+(local-file-absolute-file-name file)" port)))
+     (mkdir "dir")
+     (chdir "dir")
+     (symlink "../code.scm" "link-to-code.scm")
+     ;; call 'local-file' through symlink
+     (primitive-load (string-append tmp-dir "/dir/link-to-code.scm")))))
+
 (test-assert "one plain file"
   (let* ((file     (plain-file "hi" "Hello, world!"))
          (exp      (gexp (display (ungexp file))))

base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a
-- 
2.45.2





Information forwarded to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 1 Sep 2024 14:15:02 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Sep 01 10:15:01 2024
Received: from localhost ([127.0.0.1]:35786 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sklM5-00015r-GU
	for submit <at> debbugs.gnu.org; Sun, 01 Sep 2024 10:15:01 -0400
Received: from tobias.gr ([80.241.217.52]:36264)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <me@HIDDEN>) id 1sklM2-00015g-AU
 for 72867 <at> debbugs.gnu.org; Sun, 01 Sep 2024 10:15:00 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; s=2018; bh=5O+Fa6jkFtARe
 LJ52y/OyWdOrO67mJNMiiF468UXlks=; h=date:references:in-reply-to:
 subject:cc:to:from; d=tobias.gr;
 b=ntGoWP777zbmNfod8/Pus4ltBDF+zlOVfSQ
 F5eBULE03LHb89j1bYz9oAzIKWnUto+C6ad6Gsw5JY+Zjqgn54imOEvKUsWh/j9JaR2peV
 X5CUur/OpzhKay2vMB+TTFd0/rzIZ1d7+CXqBjq17omZ4EXt6C+EzLw7LdT7weoc+T2Lz1
 af3o+2JKsk0itqwXvRolKuTGXoigTBvArqZtn/8iJUG9b+S0+jTs4eixYD0aO6+Uhz9qA/
 8JlUY1HxHyc1h8/rgET3ctAQacoXxM7m3jKjHyTdVFlfDVAPayOFyoVxJqxYhes7ARF+nx
 yCy6nF7vjbMBe1WxvTHRtnYD4EA==
Received: by submission.tobias.gr (OpenSMTPD) with ESMTPSA id 6b3cc017
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Sun, 1 Sep 2024 14:13:54 +0000 (UTC)
From: Tobias Geerinckx-Rice <me@HIDDEN>
To: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>, Nigko Yerden
 <nigko.yerden@HIDDEN>, Ludovic =?utf-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Subject: Re: [bug#72867] when should local-file and current-source-directory
 not follow symlinks?
In-Reply-To: <87v7zg1uvm.fsf@HIDDEN> (pelzflorian@HIDDEN's
 message of "Sat, 31 Aug 2024 19:10:05 +0200")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <486161ee-563b-4de8-8cef-a970f5862fd0@HIDDEN>
 <87v7zg1uvm.fsf@HIDDEN>
BIMI-Selector: v=BIMI1; s=default;
Date: Sun, 01 Sep 2024 16:13:53 +0200
Message-ID: <87a5grihr2.fsf@nckx>
MIME-Version: 1.0
Content-Type: multipart/signed; boundary="=-=-=";
 micalg=pgp-sha512; protocol="application/pgp-signature"
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

--=-=-=
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Hi,

pelzflorian (Florian Pelz) =E5=86=99=E9=81=93=EF=BC=9A
> If we ignored possible custom code breakage, this patch could be
> simplified

Please consider doing so, responsibly[0], if everyone agrees that=20
the current default is suboptimal.

Keeping ossified (and unintentional?) quirks around forever has a=20
cost each time someone gets bitten by unintuitive behaviour.  It=20
gets less recognition than, but eventually outweighs, any=20
immediate switching costs to out-of-tree users.

(=E2=80=A6/me quietly eyes substitute*=E2=80=A6)

Kind regards,

T G-R

[0]: With a news entry, for example.

--=-=-=
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iIMEARYKACsWIQT12iAyS4c9C3o4dnINsP+IT1VteQUCZtR2oQ0cbWVAdG9iaWFz
LmdyAAoJEA2w/4hPVW15Iy8A+gMcdyts/fQfPlp90x7hTWHEnzIlMcFbsOogOsPl
qJTfAP4ruByQ7ynQFtHzFe/f+SBw0iCqsqDEnDAPpx2AGr+ZBA==
=lDYg
-----END PGP SIGNATURE-----
--=-=-=--




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 31 Aug 2024 17:11:16 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Aug 31 13:11:16 2024
Received: from localhost ([127.0.0.1]:56013 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1skRd6-0005xx-6g
	for submit <at> debbugs.gnu.org; Sat, 31 Aug 2024 13:11:16 -0400
Received: from relay.yourmailgateway.de ([188.68.63.166]:59997)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1skRd3-0005xn-Fu
 for 72867 <at> debbugs.gnu.org; Sat, 31 Aug 2024 13:11:14 -0400
Received: from mors-relay-8202.netcup.net (localhost [127.0.0.1])
 by mors-relay-8202.netcup.net (Postfix) with ESMTPS id 4Wx1cm5qKsz3v3Y;
 Sat, 31 Aug 2024 19:06:00 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1725123960;
 bh=fdE8Dp+9R/8Uk6I7i/rKIDvKVqNf4Pu8a9eWeKGROZU=;
 h=From:To:Cc:Subject:In-Reply-To:References:Date:From;
 b=SV73tk4smMPi7sWYFPTNF19mPM0H4Wcl4UbhpNWG2oUzsVly5TgnccJVUtn/3aI/p
 3IMBfFQkP3/rR+a9YPEkHoYnxfRuhnoAXNlqAfvGjN5BjCfKEOvLcM2z6tQSyg67Yb
 BSQg7LtaV1Kh2IMP0tjMXPV8f4KtoY/RDh+0RqJUoDSya86pmveF2ko2/jIzSf+ozb
 aEbrHJzqq7ZaeMBFWLYjdRcz5ByXao24XqbgB7/5Te7scMeBcbYdzlJBQpnJlw8uKu
 ap/oFyiNFDjyXdTbfsGxymcEjzZFJpsMXOZwSz1df615z2/q2lHjuIDM7h6Rq1zjHs
 ORGdcKnHdA4pA==
Received: from policy01-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay-8202.netcup.net (Postfix) with ESMTPS id 4Wx1cm57Dlz3v3R;
 Sat, 31 Aug 2024 19:06:00 +0200 (CEST)
X-Virus-Scanned: Debian amavisd-new at policy01-mors.netcup.net
X-Spam-Flag: NO
X-Spam-Score: -2.9
X-Spam-Level: 
X-Spam-Status: No, score=-2.9 required=6.31 tests=[ALL_TRUSTED=-1,
 BAYES_00=-1.9] autolearn=ham autolearn_force=no
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy01-mors.netcup.net (Postfix) with ESMTPS id 4Wx1jc4Sn9z8tXJ;
 Sat, 31 Aug 2024 19:10:12 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id 39DE98410D;
 Sat, 31 Aug 2024 19:10:05 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
To: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: Re: [bug#72867] when should local-file and current-source-directory
 not follow symlinks?
In-Reply-To: <486161ee-563b-4de8-8cef-a970f5862fd0@HIDDEN> (Nigko Yerden's
 message of "Fri, 30 Aug 2024 19:00:38 +0500")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <486161ee-563b-4de8-8cef-a970f5862fd0@HIDDEN>
Date: Sat, 31 Aug 2024 19:10:05 +0200
Message-ID: <87v7zg1uvm.fsf@HIDDEN>
User-Agent: Gnus/5.13 (Gnus v5.13)
MIME-Version: 1.0
Content-Type: text/plain
X-Rspamd-Queue-Id: 39DE98410D
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: Oa1PvMcjrXyl22PM2W+EOHBCx8CC8Xf5Ow5AQFY/yJXS8R9KDRJDjCf3
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: Attila Lendvai <attila@HIDDEN>, 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Nigko Yerden <nigko.yerden@HIDDEN> writes:
> Attila Lendvai wrote:
>> pardon my ignorance, but can you give me a (plausible) example when
>> someone wants to load some files relative to a source file, and also
>> wants to be conscious of symlinks, and chose not to follow them? let
>> alone making that the default anywhere around such operations?
> No, I can't give you an example. The original 'current-source-directory' was
> designed not to follow symlinks. This wasn't my idea. By setting the default
> I just keep the original behavior.

I guess not following symlinks was not design but an oversight.

Profiles like .config/guix/current have lots of symlinks.  Perhaps
behavior might change when custom code is processing profiles.

If we ignored possible custom code breakage, this patch could be
simplified, but not to a one-liner, as it canonicalizes paths in both
`current-source-directory' (when not in the load-path) and
`absolute-dirname' (when in the load-path).

Regards,
Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 30 Aug 2024 14:02:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Aug 30 10:02:47 2024
Received: from localhost ([127.0.0.1]:53312 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sk2D8-0006x3-Ok
	for submit <at> debbugs.gnu.org; Fri, 30 Aug 2024 10:02:46 -0400
Received: from mail-lj1-f195.google.com ([209.85.208.195]:55735)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1sk2D5-0006wi-Bp
 for 72867 <at> debbugs.gnu.org; Fri, 30 Aug 2024 10:02:45 -0400
Received: by mail-lj1-f195.google.com with SMTP id
 38308e7fff4ca-2f40a1a2c1aso16992421fa.3
 for <72867 <at> debbugs.gnu.org>; Fri, 30 Aug 2024 07:01:46 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725026440; x=1725631240; darn=debbugs.gnu.org;
 h=content-transfer-encoding:content-language:subject:from:cc:to
 :user-agent:mime-version:date:message-id:from:to:cc:subject:date
 :message-id:reply-to;
 bh=kJ3OMO278EUQfEKmfnnA3dstb9YMzJ5a2JdWcQUvcUI=;
 b=khE2Bfh2JEkPAwCMMMZpoDhuMKuFeRyiThoqRhbNRWg4J3+WO+7T3muV56uDLfu8p4
 g7KyDJlw1Z1YZ2Fg8CFwUB7A7TXnDQtQ+IsTSeouNSCa0UseeBF09L9UicTI44R5uQe9
 x6UfAHPc3vhTWdGmFIVnN28CES8p4JWcERKtQ4SbG+Pyf4hDylIGK32/Pn8YxRI6Pm6x
 LU0e6sTPGJmcsTGDV1GqLE3STtME8qj1YzUEQKYpqq09v3cOTagfsjIShdimSVOwey3B
 cgi1RjWpi+DrDmPm6/FB6SGQK9uAQ/0x/WKdJoR/A09EjfkKmhihjckITJ4nJ9J94RY9
 MwZA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725026440; x=1725631240;
 h=content-transfer-encoding:content-language:subject:from:cc:to
 :user-agent:mime-version:date:message-id:x-gm-message-state:from:to
 :cc:subject:date:message-id:reply-to;
 bh=kJ3OMO278EUQfEKmfnnA3dstb9YMzJ5a2JdWcQUvcUI=;
 b=rPK2d8WTlyrYB3f8UHaFBqhKKVjD143NxcOOxhWrsWlRv4UVz7sSrMjVFyWHRhsXSL
 J7qYIgI7f2smQXgquZbQNAbr/UP+xqsp40lBnYl9R3kTyghDFmzRnPYjpMBw1lnNzSvO
 IT8iLnsd+l1OLOkaOPWNrI/hw/Nz4OsDnUMV4aUOPyzWJWGuBVdJ7a5xLgJCgrxRma8/
 rweEHC5f2PLNoLf+R0FARL47mDUKurXGdKmZA6bNqKwMYS/j5fVoeIL2U2PQusnyX9cM
 xvBC8CNoTymCCU4AeytnzLokdfVAejt9Ij2Y3GvaKK2A8E54wpSbIyjeOFwsRjmsQVlI
 hSmw==
X-Gm-Message-State: AOJu0Yx95YZ+e6VFhuJV5HRc6xOptF6hR3ZWTwUxXIJHTFNJJqdgGEv6
 CI0Sf3NNy7sigbudBrUFOg/h/PjZd2p9fPRvwcJVygXcCVrMaL8rJNdNsxVV
X-Google-Smtp-Source: AGHT+IEQ7iHtmdwWCQL0/1wprKWGfKe1th+IVSaymP47muiXsWbF5t0dZ8PzWa2Ex6xAYGYIUts76g==
X-Received: by 2002:a05:6512:6cf:b0:533:4b76:cb59 with SMTP id
 2adb3069b0e04-53546b9d487mr1680393e87.57.1725026439576; 
 Fri, 30 Aug 2024 07:00:39 -0700 (PDT)
Received: from [127.0.0.1] ([188.68.135.139]) by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-5354084de30sm617409e87.243.2024.08.30.07.00.38
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Fri, 30 Aug 2024 07:00:39 -0700 (PDT)
Message-ID: <486161ee-563b-4de8-8cef-a970f5862fd0@HIDDEN>
Date: Fri, 30 Aug 2024 19:00:38 +0500
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
To: Attila Lendvai <attila@HIDDEN>
From: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: [bug#72867] when should local-file and current-source-directory not
 follow symlinks?
Content-Language: en-US
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

No, I can't give you an example. The original 'current-source-directory' was
designed not to follow symlinks. This wasn't my idea. By setting the default
I just keep the original behavior.

Regards,
Nigko

Attila Lendvai wrote:
> pardon my ignorance, but can you give me a (plausible) example when someone 
> wants to load some files relative to a source file, and also wants to be 
> conscious of symlinks, and chose not to follow them? 
> 
> let alone making that the default anywhere around such operations?
> 
> --
> • attila lendvai
> • PGP: 963F 5D5F 45C7 DFCD 0A39
> --
> “An armed society is a polite society. Manners are good when one may have to 
> back up his acts with his life.”
>         — Robert Heinlein (1907–1988), 'Beyond This Horizon'





Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 30 Aug 2024 12:09:25 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Fri Aug 30 08:09:25 2024
Received: from localhost ([127.0.0.1]:52580 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sk0RE-0002ml-Av
	for submit <at> debbugs.gnu.org; Fri, 30 Aug 2024 08:09:25 -0400
Received: from mail-lf1-f67.google.com ([209.85.167.67]:49407)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1sk0RA-0002mP-Eq
 for 72867 <at> debbugs.gnu.org; Fri, 30 Aug 2024 08:09:10 -0400
Received: by mail-lf1-f67.google.com with SMTP id
 2adb3069b0e04-53349d3071eso2278401e87.2
 for <72867 <at> debbugs.gnu.org>; Fri, 30 Aug 2024 05:08:11 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1725019626; x=1725624426; darn=debbugs.gnu.org;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:cc:to:subject:user-agent:mime-version:date:message-id
 :from:to:cc:subject:date:message-id:reply-to;
 bh=5iqSmkwWCrSPZMPk1hIfa8ue+YyNIWJwUjK3KZNwsmU=;
 b=MTmuMIiq9JvRkcUrSmTn1krVuZ0pXPBaolMhMTcGdPuA9/AcBEcRuFPEcUCHvGytX5
 dJ+AGrT10QYeVgH/v/i0PBjLzNAGIwxNOgXSn0bb5to6UYGGK15BUsX9ZFADZjIBpFPR
 qhm1oDqp2jJEQUXEV1ITRQboxVRrOp3JjnPbr/OWw4BKk7QMmtA4/+rNhvASFPpnKrjD
 0AaJ43q/By5m0pcQi8jQvYnfbCMKGG0aEBeXSgKuJz+QMSDPm4Nlk9GscUTDsIZzhKOp
 wirFCPbbZFo6dRM5ElnE71461xVB7um9iFUsGFNifA0GMQbg+KaTqCikI0kGpMJjakK3
 y61A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1725019626; x=1725624426;
 h=content-transfer-encoding:in-reply-to:from:content-language
 :references:cc:to:subject:user-agent:mime-version:date:message-id
 :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
 bh=5iqSmkwWCrSPZMPk1hIfa8ue+YyNIWJwUjK3KZNwsmU=;
 b=nTPJzreYr8ODSR7l1Vr9azNSNRr/BY5wqwjcfb7iSXxZLzBDNYlUf+sloyVmlaPc5y
 X95RRuL+Y1InGczd5i/I+4YinfaCa49v8V6qKYMzFzYoRiuy57UJFQ6t+S5C2Ek8gBAi
 5YaPivBpWH8Dbk8KRWfaYX3lgfoX7wl97lYLwCF1YvPHntQvVh/3v34DENfsxohRxRz9
 Wfeoxo/l0+ixH9znavwtxIGaVMCW0WnbmaY+v8luTLhwonX1DNZN2VD5oV9lEKiwNTF8
 l0QYuAeyZZN10O1ho+XtnlJAR5KriGMb/7Dw8QsHMT/aMm6O1KsLsv0kG3LcEj4f9JYq
 asjQ==
X-Gm-Message-State: AOJu0Yxc2K4vDK9xdNyXT7jEg45bMEKklUiZ1bBw/3dnqhxtzomkt/sk
 uw+aCs0nBa7o9iwB02mQ6ywiak+9QZbpsP4v27TaKHyq0ga7PT/K
X-Google-Smtp-Source: AGHT+IFcQwkhCseaaPHr57n1F3fcX2gz3sZArX2PJu1wJlslUykyM1GecugowRSsMu92Zcu9CoPqpw==
X-Received: by 2002:a05:6512:10cc:b0:530:b760:92b3 with SMTP id
 2adb3069b0e04-53546b3fdc7mr1554176e87.31.1725019624765; 
 Fri, 30 Aug 2024 05:07:04 -0700 (PDT)
Received: from [127.0.0.1] ([188.68.135.139]) by smtp.gmail.com with ESMTPSA id
 2adb3069b0e04-535407ad56bsm572951e87.116.2024.08.30.05.07.04
 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128);
 Fri, 30 Aug 2024 05:07:04 -0700 (PDT)
Message-ID: <6650f73f-e3d7-47ed-86df-ad9fa5f8cf7d@HIDDEN>
Date: Fri, 30 Aug 2024 17:07:03 +0500
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: [bug#72867] [PATCH] gexp: Make 'local-file' follow symlinks.
To: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <87frqnhffj.fsf@HIDDEN> <87v7zjbpxa.fsf@HIDDEN>
Content-Language: en-US
From: Nigko Yerden <nigko.yerden@HIDDEN>
In-Reply-To: <87v7zjbpxa.fsf@HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
Cc: 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hello Florian,

> I contributed only the error location in a failed fix.
Discussions and testings also should be counted. Without your
suggestions I would hardly have made this patch.
Thank you for all this.

> There are currently no tests for `current-source-directory'.
> To make a test case like in test/channels.scm, we would have to make
> a new guile process or build process, I presume?
I was thinking about making a test to 'local-file'. It is natural
taking into account the problem this patch solves sits in
'local-file' bad behavior. But 'current-source-directory'
is fine already.

Regards,
Nigko



pelzflorian (Florian Pelz) wrote:
> Hello all.  Thank you to Nigko for sending the patch.
> 
> Nigko Yerden <nigko.yerden@HIDDEN> writes:
>> This patch is the result of collective work of
>> Florian Pelz <pelzflorian@HIDDEN> and
>> Nigko Yerden <nigko.yerden@HIDDEN>
> 
> All real contribution to this patch is Nigko’s work.
> I contributed only the error location in a failed fix.
> 
> 
> Ludovic Courtès <ludo@HIDDEN> writes:
>> I haven’t read the thread above.  Could you come up with a test case
>> that shows the problem being fixed?  (That is, the test should fail when
>> run on current ‘master’.)
> 
> Nigko sums up the fixed issue in
> <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00071.html>:
>> pelzflorian (Florian Pelz) wrote:
>>> Nonsense; it must have worked; 7.7 Wrapping Up lists
>>> https://git.savannah.gnu.org/cgit/guile.git/tree/.guix/modules/guile-package.scm?id=cd57379b3df636198d8cd8e76c1bfbc523762e79
>>> as proof.
>> […]
>> For me pulling from this channel with subsequent
>>
>> $ guix build guile@HIDDEN
>>
>> throws an error ("No such file or directory" "GUILE-VERSION"). However,
>>
>> $ GUILE_LOAD_PATH= guix build guile@HIDDEN
>>
>> , which emulates system without [1] in Guile load path, works like a charm.
>> Thus, this repository behaves exactly as does the main branch of [2].
>>
>> Perhaps many systems (e.g. Guix on foreign distributions) indeed does not
>> have [1] in Guile load path, and thus recipe from the Cookbook works for them.
>>     Regards,
>> Nigko
>>
>> [1] ~/.config/guix/current/share/guile/site/3.0/
>> [2] https://gitlab.com/anigko/test-channel.git
> 
> There are currently no tests for `current-source-directory'.
> To make a test case like in test/channels.scm, we would have to make
> a new guile process or build process, I presume?
> 
> Regards,
> Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 29 Aug 2024 10:11:22 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Aug 29 06:11:22 2024
Received: from localhost ([127.0.0.1]:50505 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sjc7d-0001oB-K6
	for submit <at> debbugs.gnu.org; Thu, 29 Aug 2024 06:11:21 -0400
Received: from relay.yourmailgateway.de ([188.68.63.170]:58929)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <pelzflorian@HIDDEN>) id 1sjc7b-0001o1-54
 for 72867 <at> debbugs.gnu.org; Thu, 29 Aug 2024 06:11:20 -0400
Received: from mors-relay8203.netcup.net (localhost [127.0.0.1])
 by mors-relay8203.netcup.net (Postfix) with ESMTPS id 4WvcV63LkPz8bbD;
 Thu, 29 Aug 2024 10:10:22 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=pelzflorian.de;
 s=key2; t=1724926222;
 bh=irQg7Q+06gU3rzAqSd89qSBW7btHpUce6WwqLQv8Fes=;
 h=From:Cc:Subject:In-Reply-To:References:Date:From;
 b=DOlM82GtLXCrzv7GUnOLMSxO/qwzvPB3gySA4NVtmQnUGRbHczd974fzkDrpw0NCN
 kCbefZZWFx8xlPj7MSBB7GwGiUZsghMVQt+xjSC6OgxZ0uxw9I2EOc+sB+JV1oveyp
 BB4LZC3WLmT+Ud7vExBDlfK1FRpRC2tAkvWwIJ6yya2RBCZXX2NoGIu0TJpAp5Zggb
 jIVDgATCgrenjoKDH9RzXIaz6wlxUSm6m+htXh2q+bPHxDFMQvJI3h1r2n1X85JwLl
 p3XfuDmc/YNTLdAEZ6iL/sU8ifmZ5SOABM9qTcTQwLZciwDiIvWU3Y/SqWbnRmZ8hm
 iGj9ciXWXyWDQ==
Received: from policy02-mors.netcup.net (unknown [46.38.225.35])
 by mors-relay8203.netcup.net (Postfix) with ESMTPS id 4WvcV62chjz8bXt;
 Thu, 29 Aug 2024 10:10:22 +0000 (UTC)
Received: from mxe217.netcup.net (unknown [10.243.12.53])
 (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
 (No client certificate requested)
 by policy02-mors.netcup.net (Postfix) with ESMTPS id 4WvcV51cHVz8svY;
 Thu, 29 Aug 2024 12:10:21 +0200 (CEST)
Received: from florianhp (ipb2186896.dynamic.kabel-deutschland.de
 [178.24.104.150])
 by mxe217.netcup.net (Postfix) with ESMTPSA id 9158C83BE5;
 Thu, 29 Aug 2024 12:10:10 +0200 (CEST)
From: "pelzflorian (Florian Pelz)" <pelzflorian@HIDDEN>
Subject: Re: [bug#72867] [PATCH] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <87frqnhffj.fsf@HIDDEN> ("Ludovic =?utf-8?Q?Court=C3=A8s=22'?=
 =?utf-8?Q?s?= message of "Thu, 29 Aug 2024 11:00:16 +0200")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 <87frqnhffj.fsf@HIDDEN>
zTo: Ludovic =?utf-8?Q?Court=C3=A8s?= <ludo@HIDDEN>
Date: Thu, 29 Aug 2024 12:10:09 +0200
Message-ID: <87v7zjbpxa.fsf@HIDDEN>
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-Rspamd-Queue-Id: 9158C83BE5
X-Rspamd-Server: rspamd-worker-8404
X-NC-CID: ZJRTjauYQW1/W59dknmD4kQ5n58/2CLLOd1Fs3fI281t+xX96T6tTAbx
X-Spam-Score: 1.2 (+)
X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org",
 has NOT identified this incoming email as spam.  The original
 message has been attached to this so you can view it or label
 similar future email.  If you have any questions, see
 the administrator of that system for details.
 Content preview:  Hello all. Thank you to Nigko for sending the patch. Nigko
 Yerden <nigko.yerden@HIDDEN> writes: > This patch is the result of
 collective
 work of > Florian Pelz <pelzflorian@HIDDEN> and > Nigko Yerden
 <nigko.yerden@HIDDEN>
 Content analysis details:   (1.2 points, 10.0 required)
 pts rule name              description
 ---- ---------------------- --------------------------------------------------
 -0.0 SPF_PASS               SPF: sender matches SPF record
 -0.0 SPF_HELO_PASS          SPF: HELO matches SPF record
 1.2 MISSING_HEADERS        Missing To: header
X-Debbugs-Envelope-To: 72867
Cc: Josselin Poiret <dev@HIDDEN>,
 Simon Tournier <zimon.toutoune@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>,
 Tobias Geerinckx-Rice <me@HIDDEN>, Nigko Yerden <nigko.yerden@HIDDEN>,
 Christopher Baines <guix@HIDDEN>, 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.2 (/)

Hello all.  Thank you to Nigko for sending the patch.

Nigko Yerden <nigko.yerden@HIDDEN> writes:
> This patch is the result of collective work of
> Florian Pelz <pelzflorian@HIDDEN> and
> Nigko Yerden <nigko.yerden@HIDDEN>

All real contribution to this patch is Nigko=E2=80=99s work.
I contributed only the error location in a failed fix.


Ludovic Court=C3=A8s <ludo@HIDDEN> writes:
> I haven=E2=80=99t read the thread above.  Could you come up with a test c=
ase
> that shows the problem being fixed?  (That is, the test should fail when
> run on current =E2=80=98master=E2=80=99.)

Nigko sums up the fixed issue in
<https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00071.html>:
> pelzflorian (Florian Pelz) wrote:
>> Nonsense; it must have worked; 7.7 Wrapping Up lists
>> https://git.savannah.gnu.org/cgit/guile.git/tree/.guix/modules/guile-pac=
kage.scm?id=3Dcd57379b3df636198d8cd8e76c1bfbc523762e79
>> as proof.
> [=E2=80=A6]
> For me pulling from this channel with subsequent
>
> $ guix build guile@HIDDEN
>
> throws an error ("No such file or directory" "GUILE-VERSION"). However,
>
> $ GUILE_LOAD_PATH=3D guix build guile@HIDDEN
>
> , which emulates system without [1] in Guile load path, works like a char=
m.
> Thus, this repository behaves exactly as does the main branch of [2].
>
> Perhaps many systems (e.g. Guix on foreign distributions) indeed does not
> have [1] in Guile load path, and thus recipe from the Cookbook works for =
them.
>    Regards,
> Nigko
>
> [1] ~/.config/guix/current/share/guile/site/3.0/
> [2] https://gitlab.com/anigko/test-channel.git

There are currently no tests for `current-source-directory'.
To make a test case like in test/channels.scm, we would have to make
a new guile process or build process, I presume?

Regards,
Florian




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 29 Aug 2024 09:01:29 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Aug 29 05:01:29 2024
Received: from localhost ([127.0.0.1]:50402 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sjb21-00087m-9T
	for submit <at> debbugs.gnu.org; Thu, 29 Aug 2024 05:01:29 -0400
Received: from eggs.gnu.org ([209.51.188.92]:54472)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1sjb1y-00087S-OP
 for 72867 <at> debbugs.gnu.org; Thu, 29 Aug 2024 05:01:27 -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 <ludo@HIDDEN>)
 id 1sjb0z-00028b-QC; Thu, 29 Aug 2024 05:00:25 -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=PfyPV5Pt5ezeleVuwI3qMH8kpq12NgRaOAIdfRCrDtA=; b=JmttLIrM78Ee/iK2UdIJ
 hPKEf9KSepvrK1LcT3iqQJMbjaaxsbq50otcPiwZbtXcwspO6ua2UZjh7RbbZWvmFJ+fcMzHXoGfk
 umaJh6z2oZGT+1hDralDyrt9sFbicMkmGCgcQetaUaVGpQFQuDQ18baTiJ6laKfSUXqhrYK6EzvxR
 kf42TNC4r3ujupQtLqOCMJC4UIXNSM9lzcwwwBOFZ32ByOOiz2ifYXVtLnmKs2acCdbO44ZbsgjwV
 NdaWsCKIEdf5apSPmCiIlke3r+xYWU3Uou0F4K+k+Lho/55Q0Eb1M2/RV8/4WMOMYIoS6YXIX+NcK
 jRDhjO5oKCcnDQ==;
From: =?utf-8?Q?Ludovic_Court=C3=A8s?= <ludo@HIDDEN>
To: Nigko Yerden <nigko.yerden@HIDDEN>
Subject: Re: [bug#72867] [PATCH] gexp: Make 'local-file' follow symlinks.
In-Reply-To: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
 (Nigko Yerden's message of "Thu, 29 Aug 2024 11:06:14 +0500")
References: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
Date: Thu, 29 Aug 2024 11:00:16 +0200
Message-ID: <87frqnhffj.fsf@HIDDEN>
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-Spam-Score: -2.3 (--)
X-Debbugs-Envelope-To: 72867
Cc: Josselin Poiret <dev@HIDDEN>,
 Simon Tournier <zimon.toutoune@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>,
 Tobias Geerinckx-Rice <me@HIDDEN>, Christopher Baines <guix@HIDDEN>,
 72867 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -3.3 (---)

Hi Nigko,

Nigko Yerden <nigko.yerden@HIDDEN> skribis:

> Fixes <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.htm=
l>
>
> While the issue can be easily fixed (a one line change in 'absolute-dirna=
me')
> by changing 'current-source-directory' so that it always follows symlinks,
> such a change may break someone else's code. Instead, this patch keeps the
> original behavior of 'current-source-directory' macro and adds optional
> 'follow-symlinks?' argument to it.
>
> This patch is the result of collective work of
> Florian Pelz <pelzflorian@HIDDEN> and
> Nigko Yerden <nigko.yerden@HIDDEN>

I haven=E2=80=99t read the thread above.  Could you come up with a test case
that shows the problem being fixed?  (That is, the test should fail when
run on current =E2=80=98master=E2=80=99.)

That will allow us to =E2=80=9Cformalize=E2=80=9D the issue and to make sur=
e it doesn=E2=80=99t
come back later.

Thanks for your work,
Ludo=E2=80=99.




Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at 72867 <at> debbugs.gnu.org:


Received: (at 72867) by debbugs.gnu.org; 29 Aug 2024 07:02:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Aug 29 03:02:47 2024
Received: from localhost ([127.0.0.1]:50213 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sjZB8-0004W2-VD
	for submit <at> debbugs.gnu.org; Thu, 29 Aug 2024 03:02:47 -0400
Received: from mail-40136.proton.ch ([185.70.40.136]:47287)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <attila@HIDDEN>) id 1sjZB6-0004Vn-4X
 for 72867 <at> debbugs.gnu.org; Thu, 29 Aug 2024 03:02:45 -0400
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lendvai.name;
 s=protonmail2; t=1724914902; x=1725174102;
 bh=PGTZpIx+a0VeOc16u6v15+mwwOT8/cpF1Z+THqTRqyI=;
 h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:
 Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;
 b=SBu2xaMfLJ6pVjZm1plqPP/8tStzBqYoxvjqKwf8rgWaFN8n2Iio9Eal2fzT5HgmF
 kEXkzSQ2LlDdb3nf08jZwDv132wz2BYDIsV/lqvSZ7JX2EKQvkmK4vZdTZ9FrtejCq
 iPo3LMo9ZKSbRkKV6wYVESKXgSmbqLoWwWFy9Lq7NkaeytX9o2n9qAGMh9tGYUJYP0
 PNlmtOVFmtM4Vh4dJjwbAUT2lToJAoPLmob1dOSmU9+kFjtVA5i5w3vzyPgoXm6Ohe
 PwZUUDq9kMXnsAiSfTCqpYvhtyhYawMgr23IRh++dIm4SyddNHjQG5W6Wj40M3hJzX
 sN/1coqTr2mjg==
Date: Thu, 29 Aug 2024 07:01:37 +0000
To: "72867 <at> debbugs.gnu.org" <72867 <at> debbugs.gnu.org>
From: Attila Lendvai <attila@HIDDEN>
Subject: when should local-file and current-source-directory not follow
 symlinks?
Message-ID: <TOTHbuZY2D8kbEufD-xK2Gfwm277iOpbXgTLLaG8_SqglJR5FP_H4mPv7huc8iTj9cn6LCGED2AS92L_nsMtzDUUWH7srYQaGCLVL43FizY=@lendvai.name>
Feedback-ID: 28384833:user:proton
X-Pm-Message-ID: 39dfcdde4cc72988bf0b2e81f57d00062f3de68b
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 72867
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

pardon my ignorance, but can you give me a (plausible) example when someone=
 wants to load some files relative to a source file, and also wants to be c=
onscious of symlinks, and chose not to follow them?=20

let alone making that the default anywhere around such operations?

--
=E2=80=A2 attila lendvai
=E2=80=A2 PGP: 963F 5D5F 45C7 DFCD 0A39
--
=E2=80=9CAn armed society is a polite society. Manners are good when one ma=
y have to back up his acts with his life.=E2=80=9D
=09=E2=80=94 Robert Heinlein (1907=E2=80=931988), 'Beyond This Horizon'





Information forwarded to guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 29 Aug 2024 06:09:21 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Thu Aug 29 02:09:21 2024
Received: from localhost ([127.0.0.1]:50151 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1sjYLQ-000310-Kh
	for submit <at> debbugs.gnu.org; Thu, 29 Aug 2024 02:09:21 -0400
Received: from lists.gnu.org ([209.51.188.17]:54526)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <nigko.yerden@HIDDEN>) id 1sjYLP-00030s-6Z
 for submit <at> debbugs.gnu.org; Thu, 29 Aug 2024 02:09:19 -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 <nigko.yerden@HIDDEN>)
 id 1sjYKV-0004Sl-VV
 for guix-patches@HIDDEN; Thu, 29 Aug 2024 02:08:23 -0400
Received: from mail-vs1-xe44.google.com ([2607:f8b0:4864:20::e44])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)
 (Exim 4.90_1) (envelope-from <nigko.yerden@HIDDEN>)
 id 1sjYKU-0000Uz-6S
 for guix-patches@HIDDEN; Thu, 29 Aug 2024 02:08:23 -0400
Received: by mail-vs1-xe44.google.com with SMTP id
 ada2fe7eead31-498f08339c6so130265137.2
 for <guix-patches@HIDDEN>; Wed, 28 Aug 2024 23:08:21 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=gmail.com; s=20230601; t=1724911700; x=1725516500; darn=gnu.org;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:from:to:cc:subject:date:message-id:reply-to;
 bh=oD0kEMycY9D3pH/lPJXrrC8i6l2fRw6j7a4EobAdJUI=;
 b=aqIz3PsA1VkdLP6ZFWHhRejgJiYXB+rnYO85vishEh9p8d6fWxN2LBAynJcheXO6fS
 2s6LVvguzS5deb1bXOOJ31xtaZEZ2GTftIQLfvJOKF625+TdidaU4ICTwjnv/w4xrIiI
 8lAJ42CvB+yH8eZ3OKp+CRdps+qr2pjaCcG8QI107ZM2CCr/GXZaXkm2QwcZubjNIWkE
 IkVheoEijFO6b2Drz3bl4ArA9gxGy0vD1/ajeaC27fL7TWtNVHp7qKqrXax6I81bAcOw
 YwL4+bmz/+dKNImRNgFux2ctpbUtp0iB3le+lHccpziPj3Fqn82dLluAh+pQE2ZPZrWf
 mBVg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
 d=1e100.net; s=20230601; t=1724911700; x=1725516500;
 h=content-transfer-encoding:mime-version:message-id:date:subject:cc
 :to:from:x-gm-message-state:from:to:cc:subject:date:message-id
 :reply-to;
 bh=oD0kEMycY9D3pH/lPJXrrC8i6l2fRw6j7a4EobAdJUI=;
 b=p04SqqEPZZ7Uk8/uca0bllTA28GkQ+lTpzjWvUOf/97Xhoyt1UvHhwHSdiW+NIxzKZ
 E0duUhO+bsa2bXoWAgTIKq8zGp/KJKfVLNzUrH13dQhLqeg0D2UiZ3OfoyxhwdrqMzz0
 Q132QQ0cpPuJSIWa9c5NGxN0VDBxP0tLIFsAtXfvmwrP5hAjBH3Z6tNAUKQFXPXm93C+
 QH4otEvViI2tWQnOAkv4qRNdNN1vFXvhHP0d2VF5OmwXajiX40ljO7hsHh5+nNOO4qLi
 bMMd4xRJT1AxAd9jsfkIGzJx2TCGM41D5tU01k/3vjx0Mihwr29VJ/J2YIoWMPSXREpS
 YvcQ==
X-Gm-Message-State: AOJu0YxPgFKNEzsvMtI0msPPvYGyI7zke2R1Zk9LFN0tANGvovozA9cf
 SafXcxJ8XsvQPs53bRSSITHx2kahZ3MHSG2VafBUMZn3mlEnWIE+j1AuOOWT
X-Google-Smtp-Source: AGHT+IE5c7P1Ji3sNfZWfb+PNlIL3DPR7ITieb9oBB2e4LW4ASUuQRef8hoa3V1WSKdQaDweW3gTRA==
X-Received: by 2002:a05:6102:942:b0:48f:c062:75ae with SMTP id
 ada2fe7eead31-49a5ae57710mr2376640137.8.1724911700273; 
 Wed, 28 Aug 2024 23:08:20 -0700 (PDT)
Received: from localhost.localdomain ([212.75.155.9])
 by smtp.gmail.com with ESMTPSA id
 af79cd13be357-7a806c2aeb0sm25683585a.44.2024.08.28.23.08.18
 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
 Wed, 28 Aug 2024 23:08:19 -0700 (PDT)
From: Nigko Yerden <nigko.yerden@HIDDEN>
To: guix-patches@HIDDEN
Subject: [PATCH] gexp: Make 'local-file' follow symlinks.
Date: Thu, 29 Aug 2024 11:06:14 +0500
Message-ID: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@HIDDEN>
X-Mailer: git-send-email 2.45.2
MIME-Version: 1.0
X-Debbugs-Cc: Christopher Baines <guix@HIDDEN>, Josselin Poiret <dev@HIDDEN>, Ludovic Courtès <ludo@HIDDEN>, Mathieu Othacehe <othacehe@HIDDEN>, Simon Tournier <zimon.toutoune@HIDDEN>, Tobias Geerinckx-Rice <me@HIDDEN>
Content-Transfer-Encoding: 8bit
Received-SPF: pass client-ip=2607:f8b0:4864:20::e44;
 envelope-from=nigko.yerden@HIDDEN; helo=mail-vs1-xe44.google.com
X-Spam_score_int: -20
X-Spam_score: -2.1
X-Spam_bar: --
X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,
 RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
 T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
Cc: Nigko Yerden <nigko.yerden@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)

Fixes <https://lists.gnu.org/archive/html/guix-devel/2024-08/msg00047.html>

While the issue can be easily fixed (a one line change in 'absolute-dirname')
by changing 'current-source-directory' so that it always follows symlinks,
such a change may break someone else's code. Instead, this patch keeps the
original behavior of 'current-source-directory' macro and adds optional
'follow-symlinks?' argument to it.

This patch is the result of collective work of
Florian Pelz <pelzflorian@HIDDEN> and
Nigko Yerden <nigko.yerden@HIDDEN>

* guix/utils.scm (absolute-dirname): Add 'follow-symlinks?' mandatory
argument.
(%guix-source-root-directory): Pass #f to 'absolute-dirname'
'follow-symlinks?' argument.
(current-source-directory): Add 'follow-symlinks?' optional argument.
* guix/gexp.scm (local-file): Pass #t to 'current-source-directory'
'follow-symlinks?' argument.

Change-Id: Ieb30101275deb56b7436df444f9bc21d240fba59
---
 guix/gexp.scm  |  2 +-
 guix/utils.scm | 52 ++++++++++++++++++++++++++++----------------------
 2 files changed, 30 insertions(+), 24 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index 74b4c49f90..5911ca4815 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -508,7 +508,7 @@ (define-syntax local-file
        (string? (syntax->datum #'file))
        ;; FILE is a literal, so resolve it relative to the source directory.
        #'(%local-file file
-                      (delay (absolute-file-name file (current-source-directory)))
+                      (delay (absolute-file-name file (current-source-directory #t)))
                       rest ...))
       ((_ (assume-valid-file-name file) rest ...)
        ;; FILE is not a literal, so resolve it relative to the current
diff --git a/guix/utils.scm b/guix/utils.scm
index d8ce6ed886..b5fcf8cb28 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1110,41 +1110,47 @@ (define (canonical-newline-port port)
 
 (define (%guix-source-root-directory)
   "Return the source root directory of the Guix found in %load-path."
-  (dirname (absolute-dirname "guix/packages.scm")))
+  (dirname (absolute-dirname "guix/packages.scm" #f)))
 
 (define absolute-dirname
   ;; Memoize to avoid repeated 'stat' storms from 'search-path'.
-  (mlambda (file)
+  (mlambda (file follow-symlinks?)
     "Return the absolute name of the directory containing FILE, or #f upon
-failure."
+failure. Follow symlinks if FOLLOW-SYMLINKS? is true."
     (match (search-path %load-path file)
       (#f #f)
       ((? string? file)
-       ;; If there are relative names in %LOAD-PATH, FILE can be relative and
-       ;; needs to be canonicalized.
-       (if (string-prefix? "/" file)
-           (dirname file)
-           (canonicalize-path (dirname file)))))))
+       (if follow-symlinks?
+	   (dirname (canonicalize-path file))
+	   ;; If there are relative names in %LOAD-PATH, FILE can be relative
+	   ;; and needs to be canonicalized.
+	   (if (string-prefix? "/" file)
+               (dirname file)
+               (canonicalize-path (dirname file))))))))
 
 (define-syntax current-source-directory
   (lambda (s)
     "Return the absolute name of the current directory, or #f if it could not
-be determined."
+be determined. Do not follow symlinks if FOLLOW-SYMLINKS? is false (the default)."
+    (define (source-directory follow-symlinks?)
+      (match (assq 'filename (or (syntax-source s) '()))
+	(('filename . (? string? file-name))
+	 ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
+	 ;; can be relative.  In that case, we try to find out at run time
+	 ;; the absolute file name by looking at %LOAD-PATH; doing this at
+	 ;; run time rather than expansion time is necessary to allow files
+	 ;; to be moved on the file system.
+	 (if (string-prefix? "/" file-name)
+	     (dirname (if follow-symlinks?
+			  (canonicalize-path file-name)
+			  file-name))
+	     #`(absolute-dirname #,file-name #,follow-symlinks?)))
+	((or ('filename . #f) #f)
+	 ;; raising an error would upset Geiser users
+	 #f)))
     (syntax-case s ()
-      ((_)
-       (match (assq 'filename (or (syntax-source s) '()))
-         (('filename . (? string? file-name))
-          ;; If %FILE-PORT-NAME-CANONICALIZATION is 'relative, then FILE-NAME
-          ;; can be relative.  In that case, we try to find out at run time
-          ;; the absolute file name by looking at %LOAD-PATH; doing this at
-          ;; run time rather than expansion time is necessary to allow files
-          ;; to be moved on the file system.
-          (if (string-prefix? "/" file-name)
-              (dirname file-name)
-              #`(absolute-dirname #,file-name)))
-         ((or ('filename . #f) #f)
-          ;; raising an error would upset Geiser users
-          #f))))))
+      ((_) (source-directory #f))
+      ((_ follow-symlinks?) (source-directory #'follow-symlinks?)))))
 
 
 ;;;

base-commit: 4c49cd171e2aa06af05cf52403050b18f100867a
-- 
2.45.2





Acknowledgement sent to Nigko Yerden <nigko.yerden@HIDDEN>:
New bug report received and forwarded. Copy sent to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN. Full text available.
Report forwarded to guix@HIDDEN, dev@HIDDEN, ludo@HIDDEN, othacehe@HIDDEN, zimon.toutoune@HIDDEN, me@HIDDEN, guix-patches@HIDDEN:
bug#72867; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 12 Jan 2025 05:45:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.