Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / du / long-sloop
1 #!/bin/sh
2 # Use du to exercise a corner of fts's FTS_LOGICAL code.
3 # Show that du fails with ELOOP (Too many levels of symbolic links)
4 # when it encounters that condition.
5
6 # Copyright (C) 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/../lang-default
29
30 pwd=`pwd`
31 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
32 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
33 trap '(exit $?); exit $?' 1 2 13 15
34
35 framework_failure=0
36 mkdir -p $tmp || framework_failure=1
37 cd $tmp || framework_failure=1
38
39 # Create lots of directories, each containing a single symlink
40 # pointing at the next directory in the list.
41
42 # This number should be larger than the number of symlinks allowed in
43 # file name resolution, but not too large as a number of entries
44 # in a single directory.
45 n=400
46
47 dir_list=`seq $n`
48 mkdir $dir_list || framework_failure=1
49 file=1
50 i_minus_1=0
51 for i in $dir_list `expr $n + 1`; do
52   case $i_minus_1 in
53   0) ;;
54   *)
55     ln -s ../$i $i_minus_1/s || framework_failure=1
56     file=$file/s;;
57   esac
58   i_minus_1=$i
59 done
60 echo foo > $i
61
62 if test $framework_failure = 1; then
63   echo "$0: failure in testing framework" 1>&2
64   (exit 1); exit 1
65 fi
66
67 # If a system can handle this many symlinks in a file name,
68 # just skip this test.
69
70 # The following also serves to record in `err' the string
71 # corresponding to strerror (ELOOP).  This is necessary because while
72 # Linux/libc gives `Too many levels of symbolic links', Solaris
73 # renders it as `Number of symbolic links encountered during path
74 # name traversal exceeds MAXSYMLINKS'.
75
76 cat $file > /dev/null 2> err && \
77   {
78     cat <<EOF >&2
79 $0: Your system appears to be able to handle more than $n symlinks
80 in file name resolution, so skipping this test.
81 EOF
82     (exit 77); exit 77
83   }
84 too_many=`sed 's/.*: //' err`
85
86 fail=0
87
88 # With coreutils-5.93 there was no failure.
89 # With coreutils-5.94 we get the desired diagnostic:
90 # du: cannot access `1/s/s/s/.../s': Too many levels of symbolic links
91 du -L 1 > /dev/null 2> out1 && fail=1
92 sed "s, .1/s/s/s/[/s]*',," out1 > out || fail=1
93
94 echo "du: cannot access: $too_many" > exp || fail=1
95
96 cmp out exp || fail=1
97 test $fail = 1 && diff out exp 2> /dev/null
98
99 (exit $fail); exit $fail