From ddd83be0a4f45bf87904e4dd9d5f7e270be58c35 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 26 Apr 2024 10:52:02 -0500 Subject: [PATCH] find -size implies -type f. --- tests/find.test | 3 +++ toys/posix/find.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) 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")) { -- 2.39.2