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.
6 # Copyright (C) 2006 Free Software Foundation, Inc.
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.
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.
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/>.
21 if test "$VERBOSE" = yes; then
26 . $srcdir/../lang-default
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
34 mkdir -p $tmp || framework_failure=1
35 cd $tmp || framework_failure=1
37 # Create lots of directories, each containing a single symlink
38 # pointing at the next directory in the list.
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.
46 mkdir $dir_list || framework_failure=1
49 for i in $dir_list `expr $n + 1`; do
53 ln -s ../$i $i_minus_1/s || framework_failure=1
60 if test $framework_failure = 1; then
61 echo "$0: failure in testing framework" 1>&2
65 # If a system can handle this many symlinks in a file name,
66 # just skip this test.
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'.
74 cat $file > /dev/null 2> err && \
77 $0: Your system appears to be able to handle more than $n symlinks
78 in file name resolution, so skipping this test.
82 too_many=`sed 's/.*: //' err`
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
92 echo "du: cannot access: $too_many" > exp || fail=1
95 test $fail = 1 && diff out exp 2> /dev/null
97 (exit $fail); exit $fail