diff options
author | Gilad Arnold <garnold@google.com> | 2015-11-13 13:16:14 -0800 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-12-06 13:43:09 -0600 |
commit | f49f291939afae44bda438bf2509c7ba20a2a78f (patch) | |
tree | 77b5f213df50d6b78c84a97fe5ee114583153443 | |
parent | 9e563e1c6c053ad848a15c30efbbe8a079154fb4 (diff) | |
download | toybox-f49f291939afae44bda438bf2509c7ba20a2a78f.tar.gz |
Enable matching any perm bits.
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.
-rwxr-xr-x | tests/find.test | 8 | ||||
-rw-r--r-- | toys/posix/find.c | 30 |
2 files changed, 23 insertions, 15 deletions
diff --git a/tests/find.test b/tests/find.test index 2f17bf76..71a35067 100755 --- a/tests/find.test +++ b/tests/find.test @@ -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 diff --git a/toys/posix/find.c b/toys/posix/find.c index f6701845..3019cb60 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -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) { |