URL:
  <https://savannah.gnu.org/bugs/?65337>

                 Summary: Unexepected results from complete tests on
-mtime/-mmin/-daystart
                   Group: findutils
               Submitter: None
               Submitted: Tue 20 Feb 2024 04:58:22 PM UTC
                Category: find
                Severity: 3 - Normal
              Item Group: Test suite failure
                  Status: None
                 Privacy: Public
             Assigned to: None
         Originator Name: 
        Originator Email: r.duc...@gmail.com
             Open/Closed: Open
                 Release: 4.9.0
         Discussion Lock: Any
           Fixed Release: None


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Tue 20 Feb 2024 04:58:22 PM UTC By: Anonymous
1 the version of findutils you are using (e.g. run "find --version" and
include the output)
findutils 4.9.0

2  what you were trying to do
Making precise checks to try to understand the precise tests associated to the
primaries -mtime -mmin, -daystart

3 the exact command line that you used
 See attached file find-time-tests-.bash

4 what you expected to happen
5 precisely what did happen.
 See discussion below, the attached file find-time-tests.out and the table in
find-time-tests-results.md (Markdown)

-------------------------------------------------------------------
Dear maintainers of findutis

I would like to report the results of some tests I did (with findutils 4.9.0)
on the behavior of find with the primaries -mtime -mmin and with or without
-daystart.

My motivation was to understand the precise tests associated to the primaries
-mtime -mmin, -daystart because I found the docs incomplete/unclear [1]

I found a few unexpected results, I honestly do not know if these can be
qualified as bug(s) or as "well known features" not enough described in the
documentation to reach my comprehension (in which case you might want to
consider improving the documentation).

=== notations ===

To talk precisely about the expected behavior of find, let me first introduce
some definitions. (Please stay with me!)

Independently of the details of the internal code, the possible cases can be
treated by defining the AGE of a file and its rounded version RAGE as:

AGE:= (T0 - TM) / P
RAGE:= Floor[(T0 - TM) / P]

where:
* TM is the modification time
* T0 is "NOW" (execution time of find) or TOMORROW at 00:00
* P is the period or window
* all the times are measured in seconds.

Note that, according to the properties of Floor-rounding [2], for any integer
n the following holds. (Equivalence does not hold with the > sign!)

AGE < n is equivalent to RAGE < n
RAGE > n implies AGE > n
AGE > n implies RAGE >= n
AGE >= n implies RAGE >= n


To approach the current implementation, it is useful to remark that

(R)AGE < n is equivalent to T0 - n P < TM
(R)AGE >= n is equivalent to T0 - n P >= TM
AGE > n is equivalent to T0 - n P > TM


=== expectations ===

Now, what to expect from find with the primaries -mtime -mmin and -daystart?

* POSIX [3] states clearly that the primary -mtime n with n an unsigned
integer should be true if, with P=86400 T0=NOW, RAGE = n

The rest is not POSIX; from the docs [1]  I understand:

* -daystart -mtime n should be true if, with P=86400 T0=TOMORROW at 00:00,
RAGE = n

* For -mmin n  with n an unsigned integer true if, with P=60 T0=NOW, RAGE = n

* For -daystart -mmin n  with n an unsigned integer true if, with P=60
T0=TOMORROW at 00:00, RAGE = n

When signed numbers +n /-n are used (age ranges) I would expect something
like:

* A test -mtime/-mmin +n is true if AGE>n with P=86400/60 and T0=TOMORROW
00:00 or NOW according to if -startday is used or not. (Note that it is not
clear from the docs if RAGE > n should be used instead here : as stated the
two conditions are not equivalent)

* A test -mtime/-mmin -n is true if AGE < n with P=86400/60 and T0=TOMORROW
00:00 or NOW according to if -startday is used or not. (Note that RAGE < n is 
equivalent to AGE <n, so no ambiguity here)

=== test setup ===

To test my expectations I created the following files

* x0 modified at T0 + epsi0
* x1 modified at T0 - P/2 + epsi1
* x2 modified at T0 - P + epsi2
* x3 modified at T0 - 3/2 P + epsi3
* x4 modified at T0 - 2 P + epsi4
* x5 modified at T0 - 5/2 P + epsi5

with P=86400 for -mtime and P=60 for -mmin and I run the attached test (bash
script).

The epsiN  are small "errors", ideally zero but positive in practice. They are
due to the flow of time (find is executed after the execution of the commands
that create the files). The epsiN are larger when -daystart is not used: they
seem to have an effect in this case.

=== results ===

A Markdown file with a summary of the results is attached, but summarizing the
summary:

1) '-mmin n' and '-daystart -mmin n' with n unsigned gave UNEXPECTED results
(compatible with a one-minute left shift error in the definition of T0).

2) '-daystart -mtime -2' and '-mtime -2' finds x4,x3,x2,x1,x0 instead of
x3,x2,x1,x0. UNEXPECTED because AGE(x4) = 2 + epsilon

3) Similarly '-daystart -mtime -1' and '-mtime -1' finds x2,x1,x0 instead of
x1,x0. UNEXPECTED because AGE(x2) = 1 + epsilon

4) '-mtime -2 -mtime +1' finds x4 instead of x3: UNEXPECTED

5) '-mtime +2' finds x5, x4 instead of x5 but this could be due to the fact
that AGE(x4) is not precisely 2 due  to the flow of time in setup.

All the rest agreed with my expectation stated above.

Hope this can help in some way.

Sorry if I missed some important point (hope my report could convince to
improve the related docs, anyway).

[1] https://www.gnu.org/software/findutils/manual/html_mono
[2] https://en.wikipedia.org/wiki/Floor_and_ceiling_functions
[3] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html







    _______________________________________________________
File Attachments:


-------------------------------------------------------
Name: find-time-tests.bash  Size: 5KiB
<http://savannah.gnu.org/bugs/download.php?file_id=55722>
-------------------------------------------------------
Name: summary-find-time-tests-results.md  Size: 2KiB
<http://savannah.gnu.org/bugs/download.php?file_id=55723>
-------------------------------------------------------
Name: find-time-tests.out  Size: 11KiB
<http://savannah.gnu.org/bugs/download.php?file_id=55724>

    AGPL NOTICE

These attachments are served by Savane. You can download the corresponding
source code of Savane at
https://git.savannah.nongnu.org/cgit/administration/savane.git/snapshot/savane-24d3702d7a77e2ff4eb0f39b986d772d82c134fd.tar.gz

    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?65337>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/


Reply via email to