ls: treat --time=mtime consistently with other time selectors

* src/ls.c: Track if --time=mtime is explicitly specified,
so that we can apply the GNU extension of sorting by the
specified time, when not displaying (-l not specified),
and not explicitly sorting (-t not specified).
* tests/ls/ls-time.sh: Add / Update test cases.
Fixes https://bugs.gnu.org/71803
This commit is contained in:
Pádraig Brady
2024-06-27 18:15:02 +01:00
parent 72588b2915
commit b95c6ac7d2
2 changed files with 27 additions and 19 deletions

View File

@@ -33,11 +33,15 @@ u2='1998-01-14 12:00'
u3='1998-01-14 13:00'
touch -m -d "$t3" a || framework_failure_
touch -m -d "$t2" b || framework_failure_
touch -m -d "$t2" B || framework_failure_ # Capital to distinguish name sort
touch -m -d "$t1" c || framework_failure_
# Check default name sorting works
set $(ls a B c)
test "$*" = 'B a c' || fail=1
touch -a -d "$u3" c || framework_failure_
touch -a -d "$u2" b || framework_failure_
touch -a -d "$u2" B || framework_failure_
# Make sure A has ctime at least 1 second more recent than C's.
sleep 2
touch -a -d "$u1" a || framework_failure_
@@ -47,7 +51,9 @@ touch -a -d "$u1" a || framework_failure_
# A has ctime more recent than C.
set $(ls -c a c)
set $(ls -t -c a c)
test "$*" = 'a c' || fail=1
set $(ls -c a c) # Not specified by POSIX
test "$*" = 'a c' || fail=1
# Sleep so long in an attempt to avoid spurious failures
@@ -93,13 +99,17 @@ EOF
;;
esac
set $(ls -ut a b c)
test "$*" = 'c b a' && : || fail=1
test $fail = 1 && ls -l --full-time --time=access a b c
set $(ls -ut a B c)
test "$*" = 'c B a' || fail=1
set $(ls -u a B c) # not specified by POSIX
test "$*" = 'c B a' || fail=1
test $fail = 1 && ls -l --full-time --time=access a B c
set $(ls -t a b c)
test "$*" = 'a b c' && : || fail=1
test $fail = 1 && ls -l --full-time a b c
set $(ls -t a B c)
test "$*" = 'a B c' || fail=1
set $(ls --time=mtime a B c)
test "$*" = 'a B c' || fail=1
test $fail = 1 && ls -l --full-time a B c
# Now, C should have ctime more recent than A.
set $(ls -ct a c)