1#!/bin/sh 2# Test some of ls's sorting options. 3 4# Copyright (C) 1998-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ ls 21 22# Avoid any possible glitches due to daylight-saving changes near the 23# timestamps used during the test. 24TZ=UTC0 25export TZ 26 27t1='1998-01-15 21:00' 28t2='1998-01-15 22:00' 29t3='1998-01-15 23:00' 30 31u1='1998-01-14 11:00' 32u2='1998-01-14 12:00' 33u3='1998-01-14 13:00' 34 35touch -m -d "$t3" a || framework_failure_ 36touch -m -d "$t2" b || framework_failure_ 37touch -m -d "$t1" c || framework_failure_ 38 39touch -a -d "$u3" c || framework_failure_ 40touch -a -d "$u2" b || framework_failure_ 41# Make sure A has ctime at least 1 second more recent than C's. 42sleep 2 43touch -a -d "$u1" a || framework_failure_ 44# Updating the atime is usually enough to update the ctime, but on 45# Solaris 10's tmpfs, ctime is not updated, so force an update here: 46{ ln a a-ctime && rm a-ctime; } || framework_failure_ 47 48 49# A has ctime more recent than C. 50set $(ls -c a c) 51test "$*" = 'a c' || fail=1 52 53# Sleep so long in an attempt to avoid spurious failures 54# due to NFS caching and/or clock skew. 55sleep 2 56 57# Create a link, updating c's ctime. 58ln c d || framework_failure_ 59 60# Before we go any further, verify that touch's -m option works. 61set -- $(ls --full -l --time=mtime a) 62case "$*" in 63 *" $t3:00.000000000 +0000 a") ;; 64 *) 65 # This might be what's making HPUX 11 systems fail this test. 66 cat >&2 << EOF 67A basic test of touch -m has just failed, so the subsequent 68tests in this file will not be run. 69 70In the output below, the date of last modification for 'a' should 71have been $t3. 72EOF 73 ls --full -l a 74 skip_ "touch -m -d '$t3' didn't work" 75 ;; 76esac 77 78# Ensure that touch's -a option works. 79set -- $(ls --full -lu a) 80case "$*" in 81 *" $u1:00.000000000 +0000 a") ;; 82 *) 83 # This might be what's making HPUX 11 systems fail this test. 84 cat >&2 << EOF 85A fundamental touch -a test has just failed, so the subsequent 86tests in this file will not be run. 87 88In the output below, the date of last access for 'a' should 89have been $u1. 90EOF 91 ls --full -lu a 92 Exit 77 93 ;; 94esac 95 96set $(ls -ut a b c) 97test "$*" = 'c b a' && : || fail=1 98test $fail = 1 && ls -l --full-time --time=access a b c 99 100set $(ls -t a b c) 101test "$*" = 'a b c' && : || fail=1 102test $fail = 1 && ls -l --full-time a b c 103 104# Now, C should have ctime more recent than A. 105set $(ls -ct a c) 106if test "$*" = 'c a'; then 107 : ok 108else 109 # In spite of documentation, (e.g., stat(2)), neither link nor chmod 110 # update a file's st_ctime on SunOS4.1.4. 111 cat >&2 << \EOF 112failed ls ctime test -- this failure is expected at least for SunOS4.1.4 113and for tmpfs file systems on Solaris 5.5.1. 114It is also expected to fail on a btrfs file system until 115https://bugzilla.redhat.com/591068 is addressed. 116 117In the output below, 'c' should have had a ctime more recent than 118that of 'a', but does not. 119EOF 120 #' 121 ls -ctl --full-time a c 122 fail=1 123fi 124 125# This check is ineffective if: 126# en_US locale is not on the system. 127# The system en_US message catalog has a specific TIME_FMT translation, 128# which was inadvertently the case between coreutils 8.1 and 8.5 inclusive. 129 130if gettext --version >/dev/null 2>&1; then 131 132 default_tf1='%b %e %Y' 133 en_tf1=$(LC_ALL=en_US gettext coreutils "$default_tf1") 134 135 if test "$default_tf1" = "$en_tf1"; then 136 LC_ALL=en_US ls -l c >en_output 137 ls -l --time-style=long-iso c >liso_output 138 if compare en_output liso_output; then 139 fail=1 140 echo "Long ISO TIME_FMT being used for en_US locale." >&2 141 fi 142 fi 143fi 144 145Exit $fail 146