From 020f3e41568d4f76544e3e1c10e1d8dd4effc424 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 18 Jun 2015 23:25:49 +0200 Subject: gexp: 'local-file' now defaults to non-recursive. Reported by Alex Kost at . * guix/gexp.scm (local-file): Change #:recursive? to default to #f. * tests/gexp.scm ("one local file", "gexp->derivation, local-file"): Adjust calls to 'add-to-store' and 'interned-file' accordingly. --- guix/gexp.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guix') diff --git a/guix/gexp.scm b/guix/gexp.scm index 10056e5a1f..b3c4166d1a 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -157,7 +157,7 @@ cross-compiling.)" (recursive? local-file-recursive?)) ;Boolean (define* (local-file file #:optional (name (basename file)) - #:key (recursive? #t)) + #:key recursive?) "Return an object representing local file FILE to add to the store; this object can be used in a gexp. FILE will be added to the store under NAME--by default the base name of FILE. -- cgit v1.2.3 From 69792b285c98dc031d0464a08f84827e3f49c7f2 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 19 Jun 2015 10:17:37 +0200 Subject: store: Memoize 'add-to-store' based on the result of 'lstat', not 'stat'. * guix/store.scm (add-to-store): Change 'stat' call to 'lstat'. Clarify docstring. --- guix/store.scm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'guix') diff --git a/guix/store.scm b/guix/store.scm index 933708defc..7b13334952 100644 --- a/guix/store.scm +++ b/guix/store.scm @@ -610,11 +610,12 @@ path." store-path))) (lambda (server basename recursive? hash-algo file-name) "Add the contents of FILE-NAME under BASENAME to the store. When -RECURSIVE? is true and FILE-NAME designates a directory, the contents of -FILE-NAME are added recursively; if FILE-NAME designates a flat file and -RECURSIVE? is true, its contents are added, and its permission bits are -kept. HASH-ALGO must be a string such as \"sha256\"." - (let* ((st (stat file-name #f)) +RECURSIVE? is false, FILE-NAME must designate a regular file--not a directory +nor a symlink. When RECURSIVE? is true and FILE-NAME designates a directory, +the contents of FILE-NAME are added recursively; if FILE-NAME designates a +flat file and RECURSIVE? is true, its contents are added, and its permission +bits are kept. HASH-ALGO must be a string such as \"sha256\"." + (let* ((st (false-if-exception (lstat file-name))) (args `(,st ,basename ,recursive? ,hash-algo)) (cache (nix-server-add-to-store-cache server))) (or (and st (hash-ref cache args)) -- cgit v1.2.3 From 7833db1f30d78aea3b7cb042723c2bd7d00e64ad Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 19 Jun 2015 10:18:44 +0200 Subject: gexp: 'local-file' canonicalizes its file argument. Reported by Alex Kost 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 deletion(-) (limited to 'guix') diff --git a/guix/gexp.scm b/guix/gexp.scm index b3c4166d1a..0b5c43e2b8 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 fee7d87d00..32031663f5 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)))) -- cgit v1.2.3