Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / du / hard-link
1 #!/bin/sh
2 # Ensure that hard-linked files are counted (and listed) only once.
3 # Likewise for excluded directories.
4 # Ensure that hard links _are_ listed twice when using --count-links.
5
6 # Copyright (C) 2003, 2006 Free Software Foundation, Inc.
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 # 02110-1301, USA.
22
23 if test "$VERBOSE" = yes; then
24   set -x
25   du --version
26 fi
27
28 . $srcdir/../envvar-check
29 . $srcdir/../lang-default
30
31 pwd=`pwd`
32 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
33 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
34 trap '(exit $?); exit $?' 1 2 13 15
35
36 framework_failure=0
37 mkdir -p $tmp || framework_failure=1
38 cd $tmp || framework_failure=1
39
40 mkdir -p dir/sub
41 ( cd dir && { echo non-empty > f1; ln f1 f2; echo non-empty > sub/F; } )
42
43 if test $framework_failure = 1; then
44   echo "$0: failure in testing framework" 1>&2
45   (exit 1); exit 1
46 fi
47
48 fail=0
49
50 # Note that for this first test, we transform f1 or f2
51 # (whichever name we find first) to f_.  That is necessary because,
52 # depending on the type of file system, du could encounter either of those
53 # two hard-linked files first, thus listing that one and not the other.
54 du -a --exclude=sub dir \
55   | sed 's/^[0-9][0-9]* //' | sed 's/f[12]/f_/' > out || fail=1
56 echo === >> out
57 du -a --exclude=sub --count-links dir \
58   | sed 's/^[0-9][0-9]* //' | sort -r >> out || fail=1
59 cat <<\EOF > exp
60 dir/f_
61 dir
62 ===
63 dir/f2
64 dir/f1
65 dir
66 EOF
67
68 cmp out exp || fail=1
69 test $fail = 1 && diff -u out exp 2> /dev/null
70
71 (exit $fail); exit $fail