Tizen 2.0 Release
[external/tizen-coreutils.git] / tests / du / long-from-unreadable
1 #!/bin/sh
2 # Show fts fails on old-fashioned systems.
3
4 # Copyright (C) 2006 Free Software Foundation, Inc.
5
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
20
21 # Show that fts (hence du, chmod, chgrp, chown) fails when all of the
22 # following are true:
23 #   - `.' is not readable
24 #   - operating on a hierarchy containing a relative name longer than PATH_MAX
25 #   - run on a system where gnulib's openat emulation must resort to using
26 #       save_cwd and restore_cwd (which fail if `.' is not readable).
27 # Thus, the following du invocation should succeed on newer Linux and
28 # Solaris systems, yet it must fail on systems lacking both openat and
29 # /proc support.  However, before coreutils-6.0 this test would fail even
30 # on Linux+PROC_FS systems because its fts implementation would revert
31 # unnecessarily to using FTS_NOCHDIR mode in this corner case.
32
33 if test "$VERBOSE" = yes; then
34   set -x
35   du --version
36 fi
37
38 . $srcdir/../envvar-check
39
40 proc_file=/proc/self/fd
41 if test ! -d $proc_file; then
42   cat <<EOF >&2
43 $0: Skipping this test.
44 It would fail, since your system lacks /proc support.
45 EOF
46   (exit 77); exit 77
47 fi
48
49 pwd=`pwd`
50 t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$
51 trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0
52 trap '(exit $?); exit $?' 1 2 13 15
53
54 framework_failure=0
55 mkdir -p $tmp || framework_failure=1
56 cd $tmp || framework_failure=1
57
58 dir=`printf '%200s\n' ' '|tr ' ' x`
59
60 # Construct a hierarchy containing a relative file with a name
61 # longer than PATH_MAX.
62 # for i in `seq 52`; do
63 #   mkdir $dir || framework_failure=1
64 #   cd $dir || framework_failure=1
65 # done
66 # cd $tmp || framework_failure=1
67
68 # Sheesh.  Bash 3.1.5 can't create this hierarchy.  I get
69 # cd: error retrieving current directory: getcwd: cannot access parent directories:
70 # Use perl instead:
71 : ${PERL=perl}
72 $PERL \
73     -e 'my $d = '$dir'; foreach my $i (1..52)' \
74     -e '  { mkdir ($d, 0700) && chdir $d or die "$!" }' \
75   || framework_failure=1
76
77 mkdir inaccessible || framework_failure=1
78 cd inaccessible || framework_failure=1
79 chmod 0 . || framework_failure=1
80
81 if test $framework_failure = 1; then
82   echo "$0: failure in testing framework" 1>&2
83   (exit 1); exit 1
84 fi
85
86 fail=0
87 du -s "$pwd/$tmp/$dir" > /dev/null || fail=1
88
89 (exit $fail); exit $fail