From: Nigko Yerden via Guix-patches <guix-patches@gnu.org>
To: 72867@debbugs.gnu.org
Cc: "Attila Lendvai" <attila@lendvai.name>,
pelzflorian <pelzflorian@pelzflorian.de>,
"Nigko Yerden" <nigko.yerden@gmail.com>,
"Christopher Baines" <guix@cbaines.net>,
"Josselin Poiret" <dev@jpoiret.xyz>,
"Ludovic Courtès" <ludo@gnu.org>,
"Mathieu Othacehe" <othacehe@gnu.org>,
"Simon Tournier" <zimon.toutoune@gmail.com>,
"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#72867] [PATCH v6] gexp: Make 'local-file' follow symlinks.
Date: Thu, 26 Sep 2024 12:07:56 +0500 [thread overview]
Message-ID: <3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@gmail.com> (raw)
In-Reply-To: <e2bf165fc2905bcc8d33d23293eb3d31f3fbe4b8.1724911574.git.nigko.yerden@gmail.com>
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
next prev parent reply other threads:[~2024-09-26 7:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 6:06 [bug#72867] [PATCH] gexp: Make 'local-file' follow symlinks Nigko Yerden
2024-08-29 7:01 ` [bug#72867] when should local-file and current-source-directory not follow symlinks? Attila Lendvai
2024-08-29 9:00 ` [bug#72867] [PATCH] gexp: Make 'local-file' follow symlinks Ludovic Courtès
2024-08-29 10:10 ` pelzflorian (Florian Pelz)
2024-08-30 12:07 ` Nigko Yerden
2024-08-30 14:00 ` [bug#72867] when should local-file and current-source-directory not follow symlinks? Nigko Yerden
2024-08-31 17:10 ` pelzflorian (Florian Pelz)
2024-09-01 14:13 ` Tobias Geerinckx-Rice via Guix-patches via
2024-09-02 4:41 ` [bug#72867] [PATCH v2] gexp: Make 'local-file' follow symlinks Nigko Yerden
2024-09-02 7:53 ` [bug#72867] [PATCH v3] " Nigko Yerden
2024-09-03 15:05 ` pelzflorian (Florian Pelz)
2024-09-05 5:06 ` Nigko Yerden
2024-09-05 4:16 ` [bug#72867] [PATCH v4] " Nigko Yerden
2024-09-06 4:17 ` [bug#72867] [PATCH v5] " Nigko Yerden
2024-09-07 7:35 ` pelzflorian (Florian Pelz)
2024-09-25 5:16 ` pelzflorian (Florian Pelz)
2024-09-26 7:07 ` Nigko Yerden via Guix-patches [this message]
2024-10-02 16:15 ` [bug#72867] [PATCH v6] " Ludovic Courtès
2024-10-03 13:22 ` pelzflorian (Florian Pelz)
2024-10-06 7:09 ` pelzflorian (Florian Pelz)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://guix.gnu.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3079fb8aa8eedc06db4c9faae9cd08774636b94d.1727334475.git.nigko.yerden@gmail.com \
--to=guix-patches@gnu.org \
--cc=72867@debbugs.gnu.org \
--cc=attila@lendvai.name \
--cc=dev@jpoiret.xyz \
--cc=guix@cbaines.net \
--cc=ludo@gnu.org \
--cc=me@tobias.gr \
--cc=nigko.yerden@gmail.com \
--cc=othacehe@gnu.org \
--cc=pelzflorian@pelzflorian.de \
--cc=zimon.toutoune@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).