reported internally as http://b/25690138 by Gilad Arnold.

-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.
From c1e69ba82382bb6c58309fcd757362968baf7d38 Mon Sep 17 00:00:00 2001
From: Elliott Hughes <[email protected]>
Date: Fri, 13 Nov 2015 13:29:58 -0800
Subject: [PATCH] Fix find -perm.

1) It read st_dev instead of st_mode.
2) It reversed the semantics of absolute vs minimal ('-' prefixed) tests.

Add tests for these, and move the "unterminated -exec" test into the "Still
fails" section because it's still dumping core for me.
---
 tests/find.test   | 17 ++++++++++++++---
 toys/posix/find.c |  4 ++--
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/tests/find.test b/tests/find.test
index 4e856f4..2f17bf7 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -8,6 +8,11 @@ touch file
 mkfifo fifo
 ln -s fifo link
 cd ..
+touch b
+
+mkdir perm
+touch perm/all-read-only
+chmod a=r perm/all-read-only
 
 #testing "name" "command" "result" "infile" "stdin"
 
@@ -23,7 +28,7 @@ testing "find -type l -o -type d -type p" "find dir -type l -o -type d -type p"
 	"dir/link\n" "" ""
 testing "find -type l ( -type d -o -type l )" \
 	"find dir -type l \( -type d -o -type l \)" "dir/link\n" "" ""
-testing "find extra parantheses" \
+testing "find extra parentheses" \
 	"find dir \( \( -type l \) \( -type d -o \( \( -type l \) \) \) \)" \
 	"dir/link\n" "" ""
 testing "find ( -type p -o -type d ) -type p" \
@@ -49,11 +54,17 @@ testing "find -type f -user -exec" \
   "find dir -type f -user $USER -exec ls {} \\;" "dir/file\n" "" ""
 testing "find -type l -newer -exec" \
   "find dir -type l -newer dir/file -exec ls {} \\;" "dir/link\n" "" ""
-testing "find unterminated -exec {}" \
-  "find dir -type f -exec ls {}" "" "" ""
+testing "find -perm (exact success)" \
+  "find perm -type f -perm 0444" "perm/all-read-only\n" "" ""
+testing "find -perm (exact failure)" \
+  "find perm -type f -perm 0400" "" "" ""
+testing "find -perm (at least)" \
+  "find perm -type f -perm -0400" "perm/all-read-only\n" "" ""
 
 # Still fails
 
+testing "find unterminated -exec {}" \
+  "find dir -type f -exec ls {}" "" "" ""
 testing "find -exec {} +" \
   "find dir -type f -exec ls {} +" "dir/file\n" "" ""
 
diff --git a/toys/posix/find.c b/toys/posix/find.c
index aca1984..f670184 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -279,9 +279,9 @@ static int do_find(struct dirtree *new)
         if (check) {
           char *m = ss[1];
           mode_t m1 = string_to_mode(m+(*m == '-'), 0),
-                 m2 = new->st.st_dev & 07777;
+                 m2 = new->st.st_mode & 07777;
 
-          if (*m != '-') m2 &= m1;
+          if (*m == '-') m2 &= m1;
           test = m1 == m2;
         }
       } else if (!strcmp(s, "type")) {
-- 
2.6.0.rc2.230.g3dd15c0

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

Reply via email to