summaryrefslogtreecommitdiff
path: root/tests/find/used.sh
blob: d061c2dc870e62624472705d71425ca9438afa83 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# Verify that find -used works.

# Copyright (C) 2020-2021 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

. "${srcdir=.}/tests/init.sh"; fu_path_prepend_
print_ver_ find

# Create sample files with the access date D=10,20,30,40 days in the future.
for d in 10 20 30 40; do
  touch -a -d "$(date -d "$d day" '+%Y-%m-%d %H:%M:%S')" t$d \
    || skip_ "creating files with future timestamp failed"

  # Check with stat(1) the access (%X) vs. the status change time (%z).
  exp="$( expr 86400 '*' $d )" \
    && x="$( stat -c "%X" t$d )" \
    && z="$( stat -c "%Z" t$d )" \
    && tdiff="$( expr "$x" - "$z" )" \
    && test "$tdiff" -ge "$exp" \
    || skip_ "cannot verify timestamps of sample files"
done
# Create another sample file with timestamp now.
touch t00 \
  || skip_ "creating sample file failed"

stat -c "Name: %n  Access: %x  Change: %z" t?0 || : # ignore error.

# Verify the output for "find -used $d".  Use even number of days to avoid
# possibly strange effects due to atime/ctime precision etc.
for d in -45 -35 -25 -15 -5 0 5 15 25 35 45 +0 +5 +15 +25 +35 +45; do
  echo "== testing: find -used $d"
  find . -type f -name 't*' -used $d > out2 \
    || fail=1
  LC_ALL=C sort out2 || framework_failure_
done > out

cat <<\EOF > exp || framework_failure_
== testing: find -used -45
./t00
./t10
./t20
./t30
./t40
== testing: find -used -35
./t00
./t10
./t20
./t30
== testing: find -used -25
./t00
./t10
./t20
== testing: find -used -15
./t00
./t10
== testing: find -used -5
./t00
== testing: find -used 0
== testing: find -used 5
== testing: find -used 15
== testing: find -used 25
== testing: find -used 35
== testing: find -used 45
== testing: find -used +0
./t10
./t20
./t30
./t40
== testing: find -used +5
./t10
./t20
./t30
./t40
== testing: find -used +15
./t20
./t30
./t40
== testing: find -used +25
./t30
./t40
== testing: find -used +35
./t40
== testing: find -used +45
EOF

compare exp out || { fail=1; cat out; }

Exit $fail