diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2011-12-24 02:17:47 -0800 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-12-24 15:05:28 +0100 |
commit | d0be2a62a38726211cd94a06fd7e9aa23a88d07d (patch) | |
tree | c47290d1473ef6221e011d2386d775ed4cfc19cc | |
parent | adfe8bb24cbdb0c0feaf69e573ba6c023921cd33 (diff) | |
download | grep-d0be2a62a38726211cd94a06fd7e9aa23a88d07d.tar.gz |
don't ignore errors when reading a directory
grep no longer silently suppresses errors when reading a directory
as if it were a text file. For example, "grep x ." now reports a
read error on most systems; formerly, it ignored the error.
Problem reported as an aside by Bob Proulx (Bug#10355).
* NEWS: Document this.
* src/main.c (grep, grepfile): Implement this. Simplify the code
considerably.
* src/system.h (is_EISDIR): Remove; no longer needed.
-rw-r--r-- | NEWS | 5 | ||||
-rw-r--r-- | src/main.c | 41 | ||||
-rw-r--r-- | src/system.h | 6 |
3 files changed, 11 insertions, 41 deletions
@@ -4,6 +4,11 @@ GNU grep NEWS -*- outline -*- ** Bug fixes + grep no longer silently suppresses errors when reading a directory + as if it were a text file. For example, "grep x ." now reports a + read error on most systems; formerly, it ignored the error. + [bug introduced in grep-2.5] + The --include, --exclude, and --exclude-dir options now handle command-line arguments more consistently. --include and --exclude apply only to non-directories and --exclude-dir applies only to @@ -1098,8 +1098,7 @@ grep (int fd, char const *file, struct stats *stats) if (! fillbuf (save, stats)) { - if (! is_EISDIR (errno, file)) - suppressible_error (filename, errno); + suppressible_error (filename, errno); return 0; } @@ -1170,8 +1169,7 @@ grep (int fd, char const *file, struct stats *stats) nlscan (beg); if (! fillbuf (save, stats)) { - if (! is_EISDIR (errno, file)) - suppressible_error (filename, errno); + suppressible_error (filename, errno); goto finish_grep; } } @@ -1252,37 +1250,10 @@ grepfile (char const *file, struct stats *stats) if (desc < 0) { int e = errno; - - if (is_EISDIR (e, file) && directories == RECURSE_DIRECTORIES) - { - if (stat (file, &stats->stat) != 0) - { - error (0, errno, "%s", file); - return 1; - } - - return grepdir (file, stats); - } - - if (!suppress_errors) - { - if (directories == SKIP_DIRECTORIES) - switch (e) - { -#if defined EISDIR - case EISDIR: - return 1; -#endif - case EACCES: - /* When skipping directories, don't worry about - directories that can't be opened. */ - if (isdir (file)) - return 1; - break; - } - } - - suppressible_error (file, e); + /* When skipping directories, don't worry about directories + that can't be opened. */ + if (! (directories == SKIP_DIRECTORIES && isdir (file))) + suppressible_error (file, e); return 1; } diff --git a/src/system.h b/src/system.h index e7afc46d..db2fea3f 100644 --- a/src/system.h +++ b/src/system.h @@ -33,12 +33,6 @@ # define HAVE_DOS_FILE_CONTENTS 1 #endif -#ifdef EISDIR -# define is_EISDIR(e, f) ((e) == EISDIR) -#else -# define is_EISDIR(e, f) 0 -#endif - #include <stdlib.h> #include <stddef.h> #include <limits.h> |