aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2017-07-03 23:35:56 +0200
committerLudovic Courtès <ludo@gnu.org>2017-07-03 23:51:23 +0200
commit960c6ce96d746cf19829ad26e092ec5dad2a5c62 (patch)
tree81894ab71d17bc3995507acf4654af5379d7bac1
parentcc1dfc202f2fefb6c2eb9467d1fc90a9154550c9 (diff)
downloadguix-960c6ce96d746cf19829ad26e092ec5dad2a5c62.tar
guix-960c6ce96d746cf19829ad26e092ec5dad2a5c62.tar.gz
discovery: Recurse into directories pointed to by a symlink.
Reported by Christopher Baines <mail@cbaines.net> and Alex Kost <alezost@gmail.com> at <https://lists.gnu.org/archive/html/guix-devel/2017-06/msg00290.html>. * guix/discovery.scm (scheme-files): When ENTRY is a symlink that doesn't end in '.scm', call 'stat' and recurse if it points to a directory. * tests/discovery.scm ("scheme-modules recurses in symlinks to directories"): New test.
-rw-r--r--guix/discovery.scm14
-rw-r--r--tests/discovery.scm14
2 files changed, 26 insertions, 2 deletions
diff --git a/guix/discovery.scm b/guix/discovery.scm
index 292df2bd9c..2741725b9d 100644
--- a/guix/discovery.scm
+++ b/guix/discovery.scm
@@ -60,11 +60,21 @@ DIRECTORY is not accessible."
(case (entry-type absolute properties)
((directory)
(append (scheme-files absolute) result))
- ((regular symlink)
- ;; XXX: We don't recurse if we find a symlink.
+ ((regular)
(if (string-suffix? ".scm" name)
(cons absolute result)
result))
+ ((symlink)
+ (cond ((string-suffix? ".scm" name)
+ (cons absolute result))
+ ((stat absolute #f)
+ =>
+ (match-lambda
+ (#f result)
+ ((= stat:type 'directory)
+ (append (scheme-files absolute)
+ result))
+ (_ result)))))
(else
result))))))
'()
diff --git a/tests/discovery.scm b/tests/discovery.scm
index 04de83f085..753e6a8979 100644
--- a/tests/discovery.scm
+++ b/tests/discovery.scm
@@ -19,6 +19,7 @@
(define-module (test-discovery)
#:use-module (guix discovery)
#:use-module (guix build-system)
+ #:use-module (guix utils)
#:use-module (srfi srfi-64)
#:use-module (ice-9 match))
@@ -32,6 +33,19 @@
((('guix 'import _ ...) ..1)
#t)))
+(test-assert "scheme-modules recurses in symlinks to directories"
+ (call-with-temporary-directory
+ (lambda (directory)
+ (mkdir (string-append directory "/guix"))
+ (symlink (string-append %top-srcdir "/guix/import")
+ (string-append directory "/guix/import"))
+
+ ;; DIRECTORY/guix/import is a symlink but we want to make sure
+ ;; 'scheme-modules' recurses into it.
+ (match (map module-name (scheme-modules directory))
+ ((('guix 'import _ ...) ..1)
+ #t)))))
+
(test-equal "scheme-modules, non-existent directory"
'()
(scheme-modules "/does/not/exist"))