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