[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

03/03: gexp: 'local-file' canonicalizes its file argument.

From: Ludovic Courtès
Subject: 03/03: gexp: 'local-file' canonicalizes its file argument.
Date: Fri, 19 Jun 2015 08:23:37 +0000

civodul pushed a commit to branch master
in repository guix.

commit 7833db1f30d78aea3b7cb042723c2bd7d00e64ad
Author: Ludovic Courtès <address@hidden>
Date:   Fri Jun 19 10:18:44 2015 +0200

    gexp: 'local-file' canonicalizes its file argument.
    Reported by Alex Kost <address@hidden>
    at <>.
    * guix/gexp.scm (local-file): Add call to 'canonicalize-path'.
    * tests/gexp.scm ("one local file, symlink"): New test.
 guix/gexp.scm  |    6 +++++-
 tests/gexp.scm |   19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/guix/gexp.scm b/guix/gexp.scm
index b3c4166..0b5c43e 100644
--- a/guix/gexp.scm
+++ b/guix/gexp.scm
@@ -167,7 +167,11 @@ designates a flat file and RECURSIVE? is true, its 
contents are added, and its
 permission bits are kept.
 This is the declarative counterpart of the 'interned-file' monadic procedure."
-  (%local-file file name recursive?))
+  ;; Canonicalize FILE so that if it's a symlink, it is resolved.  Failing to
+  ;; do that, when RECURSIVE? is #t, we could end up creating a dangling
+  ;; symlink in the store, and when RECURSIVE? is #f 'add-to-store' would just
+  ;; throw an error, both of which are inconvenient.
+  (%local-file (canonicalize-path file) name recursive?))
 (define-gexp-compiler (local-file-compiler (file local-file?) system target)
   ;; "Compile" FILE by adding it to the store.
diff --git a/tests/gexp.scm b/tests/gexp.scm
index fee7d87..3203166 100644
--- a/tests/gexp.scm
+++ b/tests/gexp.scm
@@ -109,6 +109,25 @@
             (eq? x local)))
          (equal? `(display ,intd) (gexp->sexp* exp)))))
+(test-assert "one local file, symlink"
+  (let ((file (search-path %load-path "guix.scm"))
+        (link (tmpnam)))
+    (dynamic-wind
+      (const #t)
+      (lambda ()
+        (symlink (canonicalize-path file) link)
+        (let* ((local (local-file link "my-file" #:recursive? #f))
+               (exp   (gexp (display (ungexp local))))
+               (intd  (add-to-store %store "my-file" #f
+                                    "sha256" file)))
+          (and (gexp? exp)
+               (match (gexp-inputs exp)
+                 (((x "out"))
+                  (eq? x local)))
+               (equal? `(display ,intd) (gexp->sexp* exp)))))
+      (lambda ()
+        (false-if-exception (delete-file link))))))
 (test-assert "one plain file"
   (let* ((file     (plain-file "hi" "Hello, world!"))
          (exp      (gexp (display (ungexp file))))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]