From f4966db137283dc090e189f3e7e4fdbbe153726b Mon Sep 17 00:00:00 2001 From: Martin von Gagern Date: Wed, 26 Aug 2009 11:20:02 +0200 Subject: [PATCH 1/4] Bug #27213: avoid failed assertions for non-executable directories. To: address@hidden Addresses Savannah bug #27213 - https://savannah.gnu.org/bugs/?27213 This used to fail in recent releases: 1. mkdir -p foo/bar 2. chmod a-x foo 3. find foo 4. find foo -ls Now it will print error messages for the denied permission on foo, but will not abort completely, and in 3. will even print the name foo/bar, while it won't do so in 4., as the -ls predicate requires stat information. For now, 4. will print two identical error message. This should get fixed some day. --- build-aux/.cvsignore | 1 + build-aux/.gitignore | 1 + find/ftsfind.c | 19 ++++++++++++++++++- find/util.c | 11 +++++++---- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/build-aux/.cvsignore b/build-aux/.cvsignore index f5e817b..35d182e 100644 --- a/build-aux/.cvsignore +++ b/build-aux/.cvsignore @@ -18,3 +18,4 @@ c++defs.h useless-if-before-free vc-list-files update-copyright +unused-parameter.h diff --git a/build-aux/.gitignore b/build-aux/.gitignore index 7ced4ed..be5fe6e 100644 --- a/build-aux/.gitignore +++ b/build-aux/.gitignore @@ -17,3 +17,4 @@ compile /useless-if-before-free /vc-list-files /update-copyright +/unused-parameter.h diff --git a/find/ftsfind.c b/find/ftsfind.c index d909579..4b9dca2 100644 --- a/find/ftsfind.c +++ b/find/ftsfind.c @@ -459,6 +459,23 @@ consider_visiting (FTS *p, FTSENT *ent) error_severity (1); return; } + else + { + error(0, ent->fts_errno, "%s", + safely_quote_err_filename(0, ent->fts_path)); + error_severity(1); + /* Continue despite the error, as file name without stat info + * might be better than not even processing the file name. This + * can lead to repeated error messages later on, though, if a + * predicate requires stat information. + * + * Not printing an error message here would be even more wrong, + * though, as this could cause the contents of a directory to be + * silently ignored, as the directory wouldn't be identified as + * such. + */ + } + } } @@ -467,7 +484,7 @@ consider_visiting (FTS *p, FTSENT *ent) || ent->fts_info == FTS_NS /* e.g. symlink loop */) { assert (!state.have_stat); - assert (ent->fts_info == FTS_NSOK || state.type != 0); + assert (ent->fts_info == FTS_NSOK || state.type == 0); mode = state.type; } else diff --git a/find/util.c b/find/util.c index e19df6f..9693e57 100644 --- a/find/util.c +++ b/find/util.c @@ -216,6 +216,9 @@ get_statinfo (const char *pathname, const char *name, struct stat *p) { if (!options.ignore_readdir_race || (errno != ENOENT) ) { + /* FIXME: this error message might repeat the one from + * the FTS_NS case in consider_visiting. How to avoid this? + */ error (0, errno, "%s", safely_quote_err_filename (0, pathname)); state.exit_status = 1; @@ -272,6 +275,10 @@ get_info (const char *pathname, int result = get_statinfo (pathname, state.rel_pathname, p); if (result != 0) { + return -1; /* failure. */ + } + else + { /* Verify some postconditions. We can't check st_mode for non-zero-ness because of Savannah bug #16378 (which is that broken NFS servers can return st_mode==0). */ @@ -283,10 +290,6 @@ get_info (const char *pathname, { assert (p->st_ino); } - return -1; /* failure. */ - } - else - { return 0; /* success. */ } } -- 1.7.0