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