1#!/bin/sh
2# Ensure that rm -rf removes an empty-and-inaccessible directory.
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. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20print_ver_ rm
21skip_if_root_
22
23mkdir -m0 inacc || framework_failure_
24
25# Also exercise the different code path that's taken for a directory
26# that is empty (hence removable) and unreadable.
27mkdir -m a-r -p a/unreadable || framework_failure_
28
29# This would fail for e.g., coreutils-5.93.
30rm -rf inacc || fail=1
31test -d inacc && fail=1
32
33# This would fail for e.g., coreutils-5.97.
34rm -rf a || fail=1
35test -d a && fail=1
36
37# Ensure that using rm -d removes an unreadable empty directory.
38mkdir -m a-r unreadable2 || framework_failure_
39mkdir -m0 inacc2 || framework_failure_
40
41# These would fail for coreutils-9.1 and prior.
42rm -d unreadable2 < /dev/null || fail=1
43test -d unreadable2 && fail=1
44rm -d inacc2 < /dev/null || fail=1
45test -d inacc2 && fail=1
46
47# Test the interactive code paths that are new with 9.2:
48mkdir -m0 inacc3 || framework_failure_
49
50echo n | rm ---presume-input-tty -di inacc3 > out 2>&1 || fail=1
51# decline: ensure it was not deleted, and the prompt was as expected.
52printf "rm: attempt removal of inaccessible directory 'inacc3'? " > exp
53test -d inacc3 || fail=1
54compare exp out || fail=1
55
56echo y | rm ---presume-input-tty -di inacc3 > out 2>&1 || fail=1
57# accept: ensure it **was** deleted, and the prompt was as expected.
58test -d inacc3 && fail=1
59compare exp out || fail=1
60
61Exit $fail
62