Convert tests/du/*, too.
[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-2007 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 . $srcdir/../test-lib.sh
28
29 # Create lots of directories, each containing a single symlink
30 # pointing at the next directory in the list.
31
32 # This number should be larger than the number of symlinks allowed in
33 # file name resolution, but not too large as a number of entries
34 # in a single directory.
35 n=400
36
37 dir_list=`seq $n`
38 mkdir $dir_list || framework_failure
39 file=1
40 i_minus_1=0
41 for i in $dir_list `expr $n + 1`; do
42   case $i_minus_1 in
43   0) ;;
44   *)
45     ln -s ../$i $i_minus_1/s || framework_failure
46     file=$file/s;;
47   esac
48   i_minus_1=$i
49 done
50 echo foo > $i
51
52 # If a system can handle this many symlinks in a file name,
53 # just skip this test.
54
55 # The following also serves to record in `err' the string
56 # corresponding to strerror (ELOOP).  This is necessary because while
57 # Linux/libc gives `Too many levels of symbolic links', Solaris
58 # renders it as `Number of symbolic links encountered during path
59 # name traversal exceeds MAXSYMLINKS'.
60
61 cat $file > /dev/null 2> err && \
62   {
63     cat <<EOF >&2
64 $0: Your system appears to be able to handle more than $n symlinks
65 in file name resolution, so skipping this test.
66 EOF
67     (exit 77); exit 77
68   }
69 too_many=`sed 's/.*: //' err`
70
71 fail=0
72
73 # With coreutils-5.93 there was no failure.
74 # With coreutils-5.94 we get the desired diagnostic:
75 # du: cannot access `1/s/s/s/.../s': Too many levels of symbolic links
76 du -L 1 > /dev/null 2> out1 && fail=1
77 sed "s, .1/s/s/s/[/s]*',," out1 > out || fail=1
78
79 echo "du: cannot access: $too_many" > exp || fail=1
80
81 compare out exp || fail=1
82
83 (exit $fail); exit $fail