[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] don't ignore errors when reading a directory
From: |
Paul Eggert |
Subject: |
[PATCH 2/2] don't ignore errors when reading a directory |
Date: |
Sat, 24 Dec 2011 02:17:47 -0800 |
User-agent: |
Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111124 Thunderbird/8.0 |
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 -- what drugs were we on back in the 1990s?
* src/system.h (is_EISDIR): Remove; no longer needed.
---
NEWS | 5 +++++
src/main.c | 41 ++++++-----------------------------------
src/system.h | 6 ------
3 files changed, 11 insertions(+), 41 deletions(-)
diff --git a/NEWS b/NEWS
index 32cb32e..3824159 100644
--- a/NEWS
+++ b/NEWS
@@ -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
diff --git a/src/main.c b/src/main.c
index 70197f4..1e1667a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 e7afc46..db2fea3 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>
--
1.7.6.4
- [PATCH 2/2] don't ignore errors when reading a directory,
Paul Eggert <=