1#!/bin/sh
2# Show fts fails on old-fashioned systems.
3
4# Copyright (C) 2006-2023 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 3 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, see <https://www.gnu.org/licenses/>.
18
19# Show that fts (hence du, chmod, chgrp, chown) fails when all of the
20# following are true:
21#   - '.' is not readable
22#   - operating on a hierarchy containing a relative name longer than PATH_MAX
23#   - run on a system where gnulib's openat emulation must resort to using
24#       save_cwd and restore_cwd (which fail if '.' is not readable).
25# Thus, the following du invocation should succeed on newer Linux and
26# Solaris systems, yet it must fail on systems lacking both openat and
27# /proc support.  However, before coreutils-6.0 this test would fail even
28# on Linux+PROC_FS systems because its fts implementation would revert
29# unnecessarily to using FTS_NOCHDIR mode in this corner case.
30
31. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
32print_ver_ du
33
34require_perl_
35
36# ecryptfs for example uses some of the file name space
37# for encrypting filenames, so we must check dynamically.
38name_max=$(stat -f -c %l .)
39test "$name_max" -ge '200' || skip_ "NAME_MAX=$name_max is not sufficient"
40
41proc_file=/proc/self/fd
42if test ! -d $proc_file; then
43  skip_ 'This test would fail, since your system lacks /proc support.'
44fi
45
46dir=$(printf '%200s\n' ' '|tr ' ' x)
47
48# Construct a hierarchy containing a relative file with a name
49# longer than PATH_MAX.
50# for i in $(seq 52); do
51#   mkdir $dir || framework_failure_
52#   cd $dir || framework_failure_
53# done
54# cd $tmp || framework_failure_
55
56# Sheesh.  Bash 3.1.5 can't create this hierarchy.  I get
57#   cd: error retrieving current directory: getcwd:
58#     cannot access parent directories:
59# (all on one line).
60
61cwd=$(pwd)
62# Use perl instead:
63$PERL \
64    -e 'my $d = '$dir'; foreach my $i (1..52)' \
65    -e '  { mkdir ($d, 0700) && chdir $d or die "$!" }' \
66  || framework_failure_
67
68mkdir inaccessible || framework_failure_
69cd inaccessible || framework_failure_
70chmod 0 . || framework_failure_
71
72du -s "$cwd/$dir" > /dev/null || fail=1
73
74Exit $fail
75