OSDN Git Service

Enable matching any perm bits.
authorGilad Arnold <garnold@google.com>
Fri, 13 Nov 2015 21:16:14 +0000 (13:16 -0800)
committerRob Landley <rob@landley.net>
Sun, 6 Dec 2015 19:43:09 +0000 (13:43 -0600)
Includes tests for the new feature, and a failure case for the minimal
perms test as well.

Also some typo fixing / massaging the help text so it fits in 80
columns.

tests/find.test
toys/posix/find.c

index 2f17bf7..71a3506 100755 (executable)
@@ -58,8 +58,14 @@ 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)" \
+testing "find -perm (min success)" \
   "find perm -type f -perm -0400" "perm/all-read-only\n" "" ""
+testing "find -perm (min failure)" \
+  "find perm -type f -perm -0600" "" "" ""
+testing "find -perm (any success)" \
+  "find perm -type f -perm -0444" "perm/all-read-only\n" "" ""
+testing "find -perm (any failure)" \
+  "find perm -type f -perm -0222" "" "" ""
 
 # Still fails
 
index f670184..3019cb6 100644 (file)
@@ -22,17 +22,17 @@ config FIND
     -H  Follow command line symlinks         -L  Follow all symlinks
 
     Match filters:
-    -name  PATTERN filename with wildcards   -iname      case insensitive -name
-    -path  PATTERN path name with wildcards  -ipath      case insensitive -path
-    -user  UNAME   belongs to user UNAME     -nouser     user not in /etc/passwd
-    -group GROUP   belongs to group GROUP    -nogroup    group not in /etc/group
-    -perm  [-]MODE permissons (-=at least)   -prune      ignore contents of dir
-    -size  N[c]    512 byte blocks (c=bytes) -xdev       stay in this filesystem
-    -links N       hardlink count            -atime N    accessed N days ago
-    -ctime N       created N days ago        -mtime N    modified N days ago
-    -newer FILE    newer mtime than FILE     -mindepth # at least # dirs down
-    -depth         ignore contents of dir    -maxdepth # at most # dirs down
-    -inum  N       inode number N
+    -name  PATTERN  filename with wildcards   -iname      case insensitive -name
+    -path  PATTERN  path name with wildcards  -ipath      case insensitive -path
+    -user  UNAME    belongs to user UNAME     -nouser     user ID not known
+    -group GROUP    belongs to group GROUP    -nogroup    group ID not known
+    -perm  [-/]MODE permissions (-=min /=any) -prune      ignore contents of dir
+    -size  N[c]     512 byte blocks (c=bytes) -xdev       only this filesystem
+    -links N        hardlink count            -atime N    accessed N days ago
+    -ctime N        created N days ago        -mtime N    modified N days ago
+    -newer FILE     newer mtime than FILE     -mindepth # at least # dirs down
+    -depth          ignore contents of dir    -maxdepth # at most # dirs down
+    -inum  N        inode number N
     -type [bcdflps] (block, char, dir, file, symlink, pipe, socket)
 
     Numbers N may be prefixed by a - (less than) or + (greater than):
@@ -278,11 +278,13 @@ static int do_find(struct dirtree *new)
       } else if (!strcmp(s, "perm")) {
         if (check) {
           char *m = ss[1];
-          mode_t m1 = string_to_mode(m+(*m == '-'), 0),
+          int match_min = *m == '-',
+              match_any = *m == '/';
+          mode_t m1 = string_to_mode(m+(match_min || match_any), 0),
                  m2 = new->st.st_mode & 07777;
 
-          if (*m == '-') m2 &= m1;
-          test = m1 == m2;
+          if (match_min || match_any) m2 &= m1;
+          test = match_any ? !m1 || m2 : m1 == m2;
         }
       } else if (!strcmp(s, "type")) {
         if (check) {