aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2024-04-26 10:52:02 -0500
committerRob Landley <rob@landley.net>2024-04-26 10:52:02 -0500
commitddd83be0a4f45bf87904e4dd9d5f7e270be58c35 (patch)
tree2183c7ac8a48d7edfe372ef2a8b1c8a529ec46d4
parentaedbaa5c4d451859b0e8b470e9520f722915bda0 (diff)
downloadtoybox-ddd83be0a4f45bf87904e4dd9d5f7e270be58c35.tar.gz
find -size implies -type f.
-rwxr-xr-xtests/find.test3
-rw-r--r--toys/posix/find.c3
2 files changed, 5 insertions, 1 deletions
diff --git a/tests/find.test b/tests/find.test
index d57d1910..862edc93 100755
--- a/tests/find.test
+++ b/tests/find.test
@@ -156,4 +156,7 @@ touch -d @12345 dir/one
touch -d @12346 dir/two
testing 'newerat' 'find dir -type f -newerat @12345' 'dir/two\n' '' ''
testing 'newer nano' 'find dir -type f -newerat @12345.67890' 'dir/two\n' '' ''
+ln -s one dir/three
+testing '-size implies -type f' 'find dir -size -1M | sort' \
+ 'dir/one\ndir/two\n' '' ''
rm -rf dir
diff --git a/toys/posix/find.c b/toys/posix/find.c
index 0fde9c9e..c8e68683 100644
--- a/toys/posix/find.c
+++ b/toys/posix/find.c
@@ -438,7 +438,8 @@ static int do_find(struct dirtree *new)
if (*ss != arg) free(arg);
}
} else if (!strcmp(s, "size")) {
- if (check) test = compare_numsign(new->st.st_size, 512, arg);
+ if (check) test = compare_numsign(new->st.st_size, -512, arg) &&
+ ((new->st.st_mode & S_IFMT) == S_IFREG);
} else if (!strcmp(s, "links")) {
if (check) test = compare_numsign(new->st.st_nlink, 0, arg);
} else if (!strcmp(s, "inum")) {