cp: with --no-preserve=mode ensure set-group-ID bits maintained on dirs
[coreutils.git] / tests / du / basic.sh
blob3ac0a3e8dff0036dc8a67fcf7aedb3fb968ea205
1 #!/bin/sh
2 # Compare actual numbers from du, assuming block size matches mine.
4 # Copyright (C) 2003-2024 Free Software Foundation, Inc.
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.
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.
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/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ du
22 mkdir -p a/b d d/sub || framework_failure_
24 # Ensure that these files contain more than 64 bytes, so that we don't
25 # immediately disqualify file systems (e.g., NetApp) on which smaller
26 # files take up zero file system blocks.
27 printf '%*s' 257 make-sure-the-file-is-non-empty > a/b/F || framework_failure_
28 printf %4096s x > d/1
29 cp d/1 d/sub/2
32 B=$(stat --format=%B a/b/F)
34 du --block-size=$B -a a > out || fail=1
35 echo === >> out
36 du --block-size=$B -a -S a >> out || fail=1
37 echo === >> out
38 du --block-size=$B -s a >> out || fail=1
40 f=$(stat --format=%b a/b/F)
41 b=$(stat --format=%b a/b)
42 a=$(stat --format=%b a)
43 bf=$(expr $b + $f)
44 tot=$(expr $bf + $a)
46 cat <<EOF | sed 's/ *#.*//' > exp
47 $f a/b/F
48 $bf a/b
49 $tot a
50 ===
51 $f a/b/F # size of file, a/b/F
52 $bf a/b # size of dir entry, a/b, + size of file, a/b/F
53 $a a # size of dir entry, a
54 ===
55 $tot a
56 EOF
58 compare exp out || fail=1
60 # Perform this test only if "." is on a local file system.
61 # Otherwise, it would fail e.g., on an NFS-mounted Solaris ZFS file system.
62 # Also skip local ZFS as that was seen to fail intermittently
63 # (perhaps due to async compression affecting allocations)
64 if is_local_dir_ . && ! df -T -t zfs .; then
65 rm -f out exp
66 du --block-size=$B -a d | sort -r -k2,2 > out || fail=1
67 echo === >> out
68 du --block-size=$B -S d | sort -r -k2,2 >> out || fail=1
70 t2=$(stat --format=%b d/sub/2)
71 ts=$(stat --format=%b d/sub)
72 t1=$(stat --format=%b d/1)
73 td=$(stat --format=%b d)
74 tot=$(expr $t1 + $t2 + $ts + $td)
75 d1=$(expr $td + $t1)
76 s2=$(expr $ts + $t2)
78 cat <<EOF | sed 's/ *#.*//' > exp
79 $t2 d/sub/2
80 $s2 d/sub
81 $t1 d/1
82 $tot d
83 ===
84 $s2 d/sub
85 $d1 d # d + d/1; don't count the dir. entry for d/sub
86 EOF
88 compare exp out || fail=1
91 Exit $fail