diff options
author | Ludovic Courtès <ludo@gnu.org> | 2012-01-08 16:06:35 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2012-01-08 16:16:21 +0100 |
commit | be96155b508d220efe6f419d7743cf39744ee47c (patch) | |
tree | e7e0d5acbf3807c8c4b3b433b9c3b81815cf423d /doc/ref/misc-modules.texi | |
parent | 9a38439301aac35961e8f7e316cd02a589b5956f (diff) | |
download | guile-be96155b508d220efe6f419d7743cf39744ee47c.tar.gz |
ftw: Add an `error' parameter to `file-system-fold'.
* module/ice-9/ftw.scm (errno-if-exception): New macro.
(file-system-fold): Add an `error' parameter. Wrap `opendir' and STAT
calls in `errno-if-exception' and call ERROR when appropriate.
(file-system-tree): Provide an `error' procedure. Return #f when
FILE-NAME is unreadable.
(scandir): Provide an `error' procedure.
* test-suite/tests/ftw.test (%top-builddir): New variable.
(make-file-tree, delete-file-tree): New procedures.
(with-file-tree): New macro.
("file-system-fold"): Update tests to add an `error' procedure.
["ENOENT", "EACCES", "dangling symlink and lstat", "dangling symlink
and stat"]: New tests.
("file-system-tree")["ENOENT"]: New test.
("scandir")["EACCES"]: New test.
* doc/ref/misc-modules.texi (File Tree Walk): Update `file-system-fold'
documentation.
Diffstat (limited to 'doc/ref/misc-modules.texi')
-rw-r--r-- | doc/ref/misc-modules.texi | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/doc/ref/misc-modules.texi b/doc/ref/misc-modules.texi index 532203421..00354ac73 100644 --- a/doc/ref/misc-modules.texi +++ b/doc/ref/misc-modules.texi @@ -1,7 +1,7 @@ @c -*-texinfo-*- @c This is part of the GNU Guile Reference Manual. -@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011 -@c Free Software Foundation, Inc. +@c Copyright (C) 1996, 1997, 2000, 2001, 2002, 2003, 2004, 2006, 2009, +@c 2010, 2011, 2012 Free Software Foundation, Inc. @c See the file guile.texi for copying conditions. @node Pretty Printing @@ -1180,7 +1180,7 @@ than building up a tree of entries in memory, like directly as a directory tree is traversed; in fact, @code{file-system-tree} is implemented in terms of it. -@deffn {Scheme Procedure} file-system-fold enter? leaf down up skip init file-name [stat] +@deffn {Scheme Procedure} file-system-fold enter? leaf down up skip error init file-name [stat] Traverse the directory at @var{file-name}, recursively, and return the result of the successive applications of the @var{leaf}, @var{down}, @var{up}, and @var{skip} procedures as described below. @@ -1202,6 +1202,12 @@ encountered, call @code{(@var{skip} @var{path} @var{stat} When @var{file-name} names a flat file, @code{(@var{leaf} @var{path} @var{stat} @var{init})} is returned. +When an @code{opendir} or @var{stat} call fails, call @code{(@var{error} +@var{path} @var{stat} @var{errno} @var{result})}, with @var{errno} being +the operating system error number that was raised---e.g., +@code{EACCES}---and @var{stat} either @code{#f} or the result of the +@var{stat} call for that entry, when available. + The special @file{.} and @file{..} entries are not passed to these procedures. The @var{path} argument to the procedures is a full file name---e.g., @code{"../foo/bar/gnu"}; if @var{file-name} is an absolute @@ -1235,7 +1241,13 @@ to `du --apparent-size' with GNU Coreutils.)" ;; Likewise for skipped directories. (define (skip name stat result) result) - (file-system-fold enter? leaf down up skip + ;; Ignore unreadable files/directories but warn the user. + (define (error name stat errno result) + (format (current-error-port) "warning: ~a: ~a~%" + name (strerror errno)) + result) + + (file-system-fold enter? leaf down up skip error 0 ; initial counter is zero bytes file-name)) |