summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@ubuntu.com>2009-05-07 22:11:09 +0100
committerJames Youngman <jay@gnu.org>2009-07-05 18:13:11 +0100
commitd62aacb1b8ed9319690d8c7959d11664bd2ea905 (patch)
tree0c997f596e75915759ea9df24536d01752f8c43b
parent7d2abda8d4bf41591f18925693474b3cd8a3f783 (diff)
downloadfindutils-d62aacb1b.tar.gz
find -prune now makes sure it has valid stat() information
* find/parser.c (parse_prune): -prune needs stat information if -depth is not in use. * find/pred.c (pred_prune): Assert that stat information is available if needed. * find/testsuite/find.posix/prune-stat.exp: New test. * find/testsuite/find.posix/prune-stat.xo: New test. * find/testsuite/Makefile.am (EXTRA_DIST_EXP, EXTRA_DIST_XO): Added prune-stat.exp, prune-stat.xo. * NEWS: Mention this bugfix. Signed-off-by: Colin Watson <cjwatson@ubuntu.com>
-rw-r--r--ChangeLog12
-rw-r--r--NEWS2
-rw-r--r--find/parser.c3
-rw-r--r--find/pred.c10
-rw-r--r--find/testsuite/Makefile.am2
-rw-r--r--find/testsuite/find.posix/prune-stat.exp7
-rw-r--r--find/testsuite/find.posix/prune-stat.xo3
7 files changed, 34 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index ff256ca..98478d4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2009-05-07 Colin Watson <cjwatson@ubuntu.com>
+
+ * find/parser.c (parse_prune): -prune needs stat information if
+ -depth is not in use.
+ * find/pred.c (pred_prune): Assert that stat information is
+ available if needed.
+ * find/testsuite/find.posix/prune-stat.exp: New test.
+ * find/testsuite/find.posix/prune-stat.xo: New test.
+ * find/testsuite/Makefile.am (EXTRA_DIST_EXP, EXTRA_DIST_XO): Added
+ prune-stat.exp, prune-stat.xo.
+ * NEWS: Mention this bugfix.
+
2009-07-05 James Youngman <jay@gnu.org>
* lib/check-regexprops.sh: New test. Run regexprops as a check,
diff --git a/NEWS b/NEWS
index 5fe3ebe..09214e0 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@ systems this way.
** Bug Fixes
+find -prune now makes sure it has valid stat() information.
+
#22708: Exit status 126 and 127 from the utility invoked from xargs
now makes xargs return 123, meaning that exit status values 126 and
127 now unambigously mean that the utility could not be run or could
diff --git a/find/parser.c b/find/parser.c
index 0f8d77e..9a3ef64 100644
--- a/find/parser.c
+++ b/find/parser.c
@@ -1985,7 +1985,8 @@ parse_prune (const struct parser_table* entry, char **argv, int *arg_ptr)
(void) arg_ptr;
our_pred = insert_primary (entry);
- our_pred->need_stat = our_pred->need_type = false;
+ if (options.do_dir_first == false)
+ our_pred->need_stat = our_pred->need_type = false;
/* -prune has a side effect that it does not descend into
the current directory. */
our_pred->side_effects = true;
diff --git a/find/pred.c b/find/pred.c
index 59cc48d..1b95959 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -1607,10 +1607,12 @@ pred_prune (const char *pathname, struct stat *stat_buf, struct predicate *pred_
(void) pathname;
(void) pred_ptr;
- if (options.do_dir_first == true && /* no effect with -depth */
- stat_buf != NULL &&
- S_ISDIR(stat_buf->st_mode))
- state.stop_at_current_level = true;
+ if (options.do_dir_first == true) { /* no effect with -depth */
+ assert (state.have_stat);
+ if (stat_buf != NULL &&
+ S_ISDIR(stat_buf->st_mode))
+ state.stop_at_current_level = true;
+ }
/* findutils used to return options.do_dir_first here, so that -prune
* returns true only if -depth is not in effect. But POSIX requires
diff --git a/find/testsuite/Makefile.am b/find/testsuite/Makefile.am
index 3180e38..29ff7de 100644
--- a/find/testsuite/Makefile.am
+++ b/find/testsuite/Makefile.am
@@ -89,6 +89,7 @@ find.posix/perm-vanilla.xo \
find.posix/posixnot.xo \
find.posix/prune.xo \
find.posix/prune-result.xo \
+find.posix/prune-stat.xo \
find.posix/sizes.xo \
find.posix/sizetype.xo \
find.posix/sv-bug-11175.xo \
@@ -207,6 +208,7 @@ find.posix/perm-vanilla.exp \
find.posix/posixnot.exp \
find.posix/prune.exp \
find.posix/prune-result.exp \
+find.posix/prune-stat.exp \
find.posix/size-invalid.exp \
find.posix/size-missing.exp \
find.posix/sizes.exp \
diff --git a/find/testsuite/find.posix/prune-stat.exp b/find/testsuite/find.posix/prune-stat.exp
new file mode 100644
index 0000000..b418d78
--- /dev/null
+++ b/find/testsuite/find.posix/prune-stat.exp
@@ -0,0 +1,7 @@
+# tests that -prune gets stat information
+exec rm -rf tmp
+exec mkdir tmp tmp/a
+exec touch tmp/b
+exec mkdir tmp/c
+find_start p {tmp -name b -prune -o -print }
+exec rm -rf tmp
diff --git a/find/testsuite/find.posix/prune-stat.xo b/find/testsuite/find.posix/prune-stat.xo
new file mode 100644
index 0000000..471c9c4
--- /dev/null
+++ b/find/testsuite/find.posix/prune-stat.xo
@@ -0,0 +1,3 @@
+tmp
+tmp/a
+tmp/c