Plus new tests.
---
 tests/find.test   | 9 +++++++++
 toys/posix/find.c | 7 ++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tests/find.test b/tests/find.test
index 25c24400..7f2e6921 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -94,4 +94,13 @@ testing "-iname (no arguments)" \
 testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \
   "dir/file\n" "" ""

+testing "-path glob" \
+  "find dir -path 'dir*e'" "dir/file\n" "" ""
+testing "-wholename glob" \
+  "find dir -wholename 'dir*e'" "dir/file\n" "" ""
+testing "-ipath glob" \
+  "find dir -ipath 'dIr*E'" "dir/file\n" "" ""
+testing "-iwholename glob" \
+  "find dir -iwholename 'dIr*E'" "dir/file\n" "" ""
+
 rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index e6facb30..bae96db5 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -328,13 +328,14 @@ static int do_find(struct dirtree *new)
     // Remaining filters take an argument
     } else {
       if (!strcmp(s, "name") || !strcmp(s, "iname")
+        || !strcmp(s, "wholename") || !strcmp(s, "iwholename")
         || !strcmp(s, "path") || !strcmp(s, "ipath"))
       {
-        int i = (*s == 'i');
+        int i = (*s == 'i'), is_path = (s[i] != 'n');
         char *arg = ss[1], *path = 0, *name = new ? new->name : arg;

         // Handle path expansion and case flattening
-        if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
+        if (new && is_path) name = path = dirtree_path(new, 0);
         if (i) {
           if ((check || !new) && name) name = strlower(name);
           if (!new) dlist_add(&TT.argdata, name);
@@ -342,7 +343,7 @@ static int do_find(struct dirtree *new)
         }

         if (check) {
-          test = !fnmatch(arg, name, FNM_PATHNAME*(s[i] == 'p'));
+          test = !fnmatch(arg, name, FNM_PATHNAME*(!is_path));
           if (i) free(name);
         }
         free(path);
-- 
2.20.1.791.gb4d0f1c61a-goog
From 370b396bfdebf06f78972a5da2739ad11e1dac6d Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Wed, 13 Feb 2019 09:02:24 -0800
Subject: [PATCH] find: fix -path/-ipath and add -wholename/-iwholename
 synonyms.

Plus new tests.
---
 tests/find.test   | 9 +++++++++
 toys/posix/find.c | 7 ++++---
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/tests/find.test b/tests/find.test
index 25c24400..7f2e6921 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -94,4 +94,13 @@ testing "-iname (no arguments)" \
 testing "" "find dir \( -iname file -o -iname missing \) -exec echo {} \;" \
   "dir/file\n" "" ""
 
+testing "-path glob" \
+  "find dir -path 'dir*e'" "dir/file\n" "" ""
+testing "-wholename glob" \
+  "find dir -wholename 'dir*e'" "dir/file\n" "" ""
+testing "-ipath glob" \
+  "find dir -ipath 'dIr*E'" "dir/file\n" "" ""
+testing "-iwholename glob" \
+  "find dir -iwholename 'dIr*E'" "dir/file\n" "" ""
+
 rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index e6facb30..bae96db5 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -328,13 +328,14 @@ static int do_find(struct dirtree *new)
     // Remaining filters take an argument
     } else {
       if (!strcmp(s, "name") || !strcmp(s, "iname")
+        || !strcmp(s, "wholename") || !strcmp(s, "iwholename")
         || !strcmp(s, "path") || !strcmp(s, "ipath"))
       {
-        int i = (*s == 'i');
+        int i = (*s == 'i'), is_path = (s[i] != 'n');
         char *arg = ss[1], *path = 0, *name = new ? new->name : arg;
 
         // Handle path expansion and case flattening
-        if (new && s[i] == 'p') name = path = dirtree_path(new, 0);
+        if (new && is_path) name = path = dirtree_path(new, 0);
         if (i) {
           if ((check || !new) && name) name = strlower(name);
           if (!new) dlist_add(&TT.argdata, name);
@@ -342,7 +343,7 @@ static int do_find(struct dirtree *new)
         }
 
         if (check) {
-          test = !fnmatch(arg, name, FNM_PATHNAME*(s[i] == 'p'));
+          test = !fnmatch(arg, name, FNM_PATHNAME*(!is_path));
           if (i) free(name);
         }
         free(path);
-- 
2.20.1.791.gb4d0f1c61a-goog

_______________________________________________
Toybox mailing list
[email protected]
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to