summaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2011-12-19 09:11:43 +0100
committerLudovic Courtès <ludo@gnu.org>2011-12-19 09:11:51 +0100
commitde92987002224276dafc0875873b30149e964828 (patch)
tree72076128582d422bdd85b2fc0c160497dc92faaa /module
parent3cc21d7995313782f6def1789ca0150e95c8363f (diff)
ftw: Clarify the behavior of `scandir' for flat files and unreadable dirs.
* module/ice-9/ftw.scm (scandir)[leaf]: Only add NAME when RESULT is a pair. [down]: Ignore RESULT. Start with #f instead of the empty list. * test-suite/tests/ftw.test ("scandir")["flat file"]: New test. * doc/ref/misc-modules.texi (File Tree Walk): Update `scandir' documentation accordingly.
Diffstat (limited to 'module')
-rw-r--r--module/ice-9/ftw.scm9
1 files changed, 5 insertions, 4 deletions
diff --git a/module/ice-9/ftw.scm b/module/ice-9/ftw.scm
index c335e9705..bbb2bbe6c 100644
--- a/module/ice-9/ftw.scm
+++ b/module/ice-9/ftw.scm
@@ -512,17 +512,18 @@ children. The optional STAT parameter defaults to `lstat'."
"Return the list of the names of files contained in directory NAME
that match predicate SELECT? (by default, all files.) The returned list
of file names is sorted according to ENTRY<?, which defaults to
-`string-locale<?'."
+`string-locale<?'. Return #f when NAME is unreadable or is not a directory."
(define (enter? name stat result)
(and stat (string=? name name)))
(define (leaf name stat result)
(if (select? name)
- (cons (basename name) result)
+ (and (pair? result) ; must have a "." entry
+ (cons (basename name) result))
result))
(define (down name stat result)
- (cons "." result))
+ (list "."))
(define (up name stat result)
(cons ".." result))
@@ -531,7 +532,7 @@ of file names is sorted according to ENTRY<?, which defaults to
;; NAME itself is not readable.
#f)
- (and=> (file-system-fold enter? leaf down up skip '() name stat)
+ (and=> (file-system-fold enter? leaf down up skip #f name stat)
(lambda (files)
(sort files entry<?))))