diff options
author | Bernhard Voelker <mail@bernhard-voelker.de> | 2021-11-24 01:57:35 +0100 |
---|---|---|
committer | Bernhard Voelker <mail@bernhard-voelker.de> | 2021-11-27 23:21:06 +0100 |
commit | 4ddb092de66a4186a097de5ab8390b2e7d167efb (patch) | |
tree | ac6d9db247cfbd63386d9f7b6f0209a042e5e0fa | |
parent | f16272db43c9d811c1b946ec8262651d43619573 (diff) | |
download | findutils-4ddb092de66a4186a097de5ab8390b2e7d167efb.tar.gz |
find: allow -files0-from input file to be empty
Do no longer output an error diagnostic when the input file of
the -files0-from option is empty.
* find/ftsfind.c (process_all_startpoints): Remove error diagnostic.
* doc/find.texi (node Starting points): Adjust documentation.
* find/find.1: Likewise.
* tests/find/files0-from.sh: Adjust test.
Suggested by Stephane Chazelas in
https://savannah.gnu.org/bugs/?60383#comment11
-rw-r--r-- | doc/find.texi | 8 | ||||
-rw-r--r-- | find/find.1 | 8 | ||||
-rw-r--r-- | find/ftsfind.c | 4 | ||||
-rwxr-xr-x | tests/find/files0-from.sh | 12 |
4 files changed, 18 insertions, 14 deletions
diff --git a/doc/find.texi b/doc/find.texi index 69572b78..8a12898e 100644 --- a/doc/find.texi +++ b/doc/find.texi @@ -410,8 +410,12 @@ The starting points in @file{file} have to be separated by ASCII NUL characters. Two consecutive NUL characters, i.e., a starting point with a Zero-length file name is not allowed and will lead to an error diagnostic followed by a non-Zero exit code later. -The given @file{file} has to contain at least one starting point, -i.e., an empty input file will be diagnosed as well. + +In the case the given @file{file} is empty, @code{find} does not process any +starting point and therefore will exit immediately after parsing the program +arguments. +This is unlike the standard invocation where @code{find} assumes the current +directory as starting point if no path argument is passed. The processing of the starting points is otherwise as usual, e.g. @code{find} will recurse into subdirectories unless otherwise prevented. diff --git a/find/find.1 b/find/find.1 index 004e9b23..d5233def 100644 --- a/find/find.1 +++ b/find/find.1 @@ -539,8 +539,12 @@ The starting points in \fIfile\fR have to be separated by ASCII NUL characters. Two consecutive NUL characters, i.e., a starting point with a Zero-length file name is not allowed and will lead to an error diagnostic followed by a non-Zero exit code later. -The given \fIfile\fR has to contain at least one starting point, -i.e., an empty input file will be diagnosed as well. + +In the case the given \fIfile\fR is empty, \fBfind\fR does not process any +starting point and therefore will exit immediately after parsing the program +arguments. +This is unlike the standard invocation where \fBfind\fR assumes the current +directory as starting point if no path argument is passed. The processing of the starting points is otherwise as usual, e.g. .B find diff --git a/find/ftsfind.c b/find/ftsfind.c index bd3b8ee8..b266a988 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -713,10 +713,6 @@ process_all_startpoints (int argc, char *argv[]) } argv_iter_done: - if (ok && options.files0_from && argv_iter_n_args (ai) <= 0) - die (EXIT_FAILURE, 0, _("file with starting points is empty: %s"), - files0_filename_quoted); - argv_iter_free (ai); if (ok && options.files0_from && (ferror (stream) || fclose (stream) != 0)) diff --git a/tests/find/files0-from.sh b/tests/find/files0-from.sh index bf54a1b2..4864a866 100755 --- a/tests/find/files0-from.sh +++ b/tests/find/files0-from.sh @@ -94,19 +94,19 @@ returns_ 1 find -files0-from / > out 2> err \ || { grep . out err; fail=1; } # Exercise an empty input file. -returns_ 1 find -files0-from /dev/null > out 2> err || fail=1 +find -files0-from /dev/null > out 2> err || fail=1 compare /dev/null out || fail=1 -grep 'file with starting points is empty:' err || fail=1 +compare /dev/null err || fail=1 # Likewise via stdin. -returns_ 1 find -files0-from - < /dev/null > out 2> err || fail=1 +find -files0-from - < /dev/null > out 2> err || fail=1 compare /dev/null out || fail=1 -grep 'file with starting points is empty:.*standard input' err || fail=1 +compare /dev/null err || fail=1 # Likewise via a pipe on stdin. -cat /dev/null | returns_ 1 find -files0-from - > out 2> err || fail=1 +cat /dev/null | find -files0-from - > out 2> err || fail=1 compare /dev/null out || fail=1 -grep 'file with starting points is empty:.*standard input' err || fail=1 +compare /dev/null err || fail=1 # With the -files0-from option, now a closing paren could be passed as first # predicate (without, it is treated as a starting point). Ensure that find(1) |