URL:
<http://savannah.gnu.org/bugs/?46815>
Summary: problem when testing file size
Project: findutils
Submitted by: None
Submitted on: Di 05 Jan 2016 06:08:51 UTC
Category: find
Severity: 3 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Originator Name:
Originator Email: [email protected]
Open/Closed: Open
Discussion Lock: Any
Release: None
Fixed Release: None
_______________________________________________________
Details:
Hi,
I noticed a strange behaviour in GNU find when testing the file
size. Let me explain the found problem with a small example:
$ dd if=/dev/zero of=foo.1k bs=1024 count=1
$ dd if=/dev/zero of=foo.24k bs=1024 count=24
$ dd if=/dev/zero of=foo.1M bs=1024 count=1024
$ # this should only find foo.1M:
$ find . -size 1M
.
./foo.24k
./foo.1k
./foo.1M
$ # this one works correctly:
$ find . -size 24k
./foo.24k
$ # all files less than 1M should be found but result is empty:
$ find . -size -1M
$ # all files are found:
$ find . -size -2M
.
./foo.24k
./foo.1k
./foo.1M
$ # a different unit also solves the issue:
$ find . -size -1024k
.
./foo.24k
./foo.1k
The problem is how pred_size() calculates the file size. When
searching for a file with a size of 1M and processing the test
files we created previously f_val is always 1:
f_val = ((1024 / 1048576) + (1024 % 1048576 != 0)) = 1
f_val = ((24576 / 1048576) + (24576 % 1048576 != 0)) = 1
f_val = ((24576 / 1048576) + (24576 % 1048576 != 0)) = 1
I fixed the problem on my system by applying this patch:
diff --git a/find/pred.c b/find/pred.c
index d633ab9..73abbec 100644
--- a/find/pred.c
+++ b/find/pred.c
@@ -956,12 +956,12 @@ bool
pred_size (const char *pathname, struct stat *stat_buf, struct predicate
*pred_ptr)
{
uintmax_t f_val;
(void) pathname;
- f_val = ((stat_buf->st_size / pred_ptr->args.size.blocksize)
- + (stat_buf->st_size % pred_ptr->args.size.blocksize != 0));
+ f_val = stat_buf->st_size / pred_ptr->args.size.blocksize;
+
switch (pred_ptr->args.size.kind)
{
case COMP_GT:
if (f_val > pred_ptr->args.size.size)
return (true);
Kind regards,
Sebastian
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?46815>
_______________________________________________
Nachricht gesendet von/durch Savannah
http://savannah.gnu.org/