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