Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 579688 - sys-apps/gentoo-functions: is_older_than: `test -nt` usage isn't in POSIX
Summary: sys-apps/gentoo-functions: is_older_than: `test -nt` usage isn't in POSIX
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal
Assignee: William Hubbs
URL:
Whiteboard:
Keywords: InVCS, PATCH
Depends on:
Blocks: nonbash
  Show dependency tree
 
Reported: 2016-04-12 08:22 UTC by SpanKY
Modified: 2024-08-12 08:11 UTC (History)
3 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
0001-Eliminate-the-bashism-that-is-the-nt-test-operator.patch (0001-Eliminate-the-bashism-that-is-the-nt-test-operator.patch,3.26 KB, patch)
2023-02-06 01:10 UTC, kfm
Details | Diff
0002-Add-a-gentoo-functions-test-suite.patch (0002-Add-a-gentoo-functions-test-suite.patch,3.73 KB, patch)
2023-02-06 01:11 UTC, kfm
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description SpanKY gentoo-dev 2016-04-12 08:22:50 UTC
the is_older_than function uses `test -nt`, but that test isn't in POSIX
Comment 1 kfm 2023-02-06 01:10:54 UTC
Created attachment 849938 [details, diff]
0001-Eliminate-the-bashism-that-is-the-nt-test-operator.patch

I already mailed this in, but attaching anyway.
Comment 2 kfm 2023-02-06 01:11:29 UTC
Created attachment 849940 [details, diff]
0002-Add-a-gentoo-functions-test-suite.patch

Ditto.
Comment 3 Larry the Git Cow gentoo-dev 2023-02-06 03:59:03 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=1553c3bc0f0c18892aa03880183e95d0aa8089e9

commit 1553c3bc0f0c18892aa03880183e95d0aa8089e9
Author:     Kerin Millar <kfm@plushkava.net>
AuthorDate: 2023-02-06 01:02:57 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-02-06 03:08:50 +0000

    Add a gentoo-functions test suite
    
    Presently, it tests only the is_older_than() function, and requires
    bash, in addition to mktemp(1) and touch(1) from GNU coreutils. Note
    that this commit does not touch the Makefile.
    
    Signed-off-by: Kerin Millar <kfm@plushkava.net>
    Bug: https://bugs.gentoo.org/579688
    Signed-off-by: Sam James <sam@gentoo.org>

 test-functions | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b6c180b9851ba94f68016836cbce2dde46e07165

commit b6c180b9851ba94f68016836cbce2dde46e07165
Author:     Kerin Millar <kfm@plushkava.net>
AuthorDate: 2023-02-06 00:59:11 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-02-06 03:08:33 +0000

    Eliminate the bashism that is the -nt test operator
    
    Presently, the is_older_than() function uses the -nt operator as part
    of a test command. As was reported by bug 579688, it is not supported by
    POSIX. In fact, there is no way to perform this kind of check with sh(1)
    and the standard utilities alone. After some deliberation, I concluded
    that relying on GNU findutils would be the best course of action. Not
    only does it provide the -newerXY predicate, but it is also required by
    PMS to begin with.
    
    The revised function works by using the -newermm predicate to compare
    any of the pathnames that it encounters against the specified reference
    path. In the event that it encounters any other path that is newer than
    the reference path, it shall immediately quit, rendering it fairly
    efficient. In fact, there is no circumstance under which more than one
    line of output needs to be read from find(1).
    
    The prior implementation would aggressively follow directories, even for
    symlinks. This seems unwise to me. Nevertheless, find(1) is given the
    -L option so as to preserve this behaviour.
    
    Considerable care has been taken to ensure that the revised function
    remains exit status compatible. I performed 50 individual tests to that
    end. One obvious difference is that directories whose names begin with
    a dot will now be recursed. I determined that there was no obviously
    apparent reason that this should be an issue. Regardless, it would be
    trivial to alter this behaviour in the future, if so neeed.
    
    Please note that it requires findutils >=4.9 as a runtime dependency,
    owing to its use of -files0-from, which is far too useful an option to
    wish to forgo. It will prefer "gfind" over "find", if the former is
    found to exist.
    
    Incidentally, the revised function is resilient to the case in which
    the sh(1) implementation does not support local. The anti-pattern of
    using local (which is undefined behaviour) to define a variable, while
    simultaneously assigning it, is becoming a most tiresome one.
    
    Signed-off-by: Kerin Millar <kfm@plushkava.net>
    Bug: https://bugs.gentoo.org/579688
    Signed-off-by: Sam James <sam@gentoo.org>

 functions.sh | 32 ++++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 8 deletions(-)
Comment 4 Larry the Git Cow gentoo-dev 2023-02-06 04:33:54 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c0879d2ebced44576710300e0baf055328f0572a

commit c0879d2ebced44576710300e0baf055328f0572a
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2023-02-06 04:33:24 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2023-02-06 04:33:46 +0000

    sys-apps/gentoo-functions: add 0.18
    
    Closes: https://bugs.gentoo.org/579688
    Signed-off-by: Sam James <sam@gentoo.org>

 sys-apps/gentoo-functions/Manifest                 |  1 +
 .../gentoo-functions/gentoo-functions-0.18.ebuild  | 27 ++++++++++++++++++++++
 2 files changed, 28 insertions(+)
Comment 5 kfm 2024-08-12 08:11:55 UTC
Just for the record, the -nt and -ot primaries have been re-introduced. For further details, please refer to:

https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=6cf0940b8d336eb35a970af2ffc819f55e3ab429