aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-04-25 00:55:01 -0500
committerRob Landley <rob@landley.net>2016-04-25 00:55:01 -0500
commit442c1853d1556610e96e41babdfb7b706f3d2ccf (patch)
treedd1ddb1b08fd498e722245540ad07c2ad2cefa88
parent25a2395e2698aebd53ad3bc4d9143cd817d8332f (diff)
downloadtoybox-442c1853d1556610e96e41babdfb7b706f3d2ccf.tar.gz
Fix find bug reported by Tom Marshall, add test for it, and while we're at it
fix two tests looking for a too-specific error message (so TEST_HOST failed).
-rwxr-xr-xtests/find.test8
-rw-r--r--toys/posix/find.c12
2 files changed, 10 insertions, 10 deletions
diff --git a/tests/find.test b/tests/find.test
index 580d1959..25c24400 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -87,7 +87,11 @@ testing "-iname FILE" \
testing "-name (no arguments)" \
- "find dir -name 2>&1" "find: '-name' needs 1 arg\n" "" ""
+ "find dir -name 2>&1 | grep -o '[-]name'" "-name\n" "" ""
testing "-iname (no arguments)" \
- "find dir -iname 2>&1" "find: '-iname' needs 1 arg\n" "" ""
+ "find dir -iname 2>&1 | grep -o '[-]iname'" "-iname\n" "" ""
+
+testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \
+ "dir/file\n" "" ""
+
rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 303aada2..3b27225d 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -320,20 +320,16 @@ static int do_find(struct dirtree *new)
// Handle path expansion and case flattening
if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
if (i) {
- if (check || !new) {
- if (name) name = strlower(name);
- if (!new) {
- dlist_add(&TT.argdata, name);
- free(path);
- } else arg = ((struct double_list *)llist_pop(&argdata))->data;
- }
+ if ((check || !new) && name) name = strlower(name);
+ if (!new) dlist_add(&TT.argdata, name);
+ else arg = ((struct double_list *)llist_pop(&argdata))->data;
}
if (check) {
test = !fnmatch(arg, name, FNM_PATHNAME*(s[i] == 'p'));
- free(path);
if (i) free(name);
}
+ free(path);
} else if (!strcmp(s, "perm")) {
if (check) {
char *m = ss[1];