From a0803c4bad6f8e11bb05effcc42ef433f4fc3f9b Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Mon, 6 Feb 2023 09:01:55 -0800 Subject: rm: --dir (-d): fix bugs in handling of empty, inaccessible directories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * src/remove.c (prompt, rm_fts): In the dir-handling code of both of these functions, relax a "get_dir_status (...) == DS_EMPTY" condition to instead test only "get_dir_status (...) != 0", enabling flow control to reach the prompt function also for unreadable directories. However, that function itself also needed special handling for this case: (prompt): Handle empty, inaccessible directories properly, deleting them with -d (--dir), and prompting about whether to delete with -i (--interactive). * tests/rm/empty-inacc.sh: Add tests for the new code. Reported by наб in bugs.debian.org/1015273 * NEWS (Bug fixes): Mention this. --- tests/rm/empty-inacc.sh | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/rm/empty-inacc.sh b/tests/rm/empty-inacc.sh index 5d6181509..807ff4d1d 100755 --- a/tests/rm/empty-inacc.sh +++ b/tests/rm/empty-inacc.sh @@ -24,8 +24,7 @@ mkdir -m0 inacc || framework_failure_ # Also exercise the different code path that's taken for a directory # that is empty (hence removable) and unreadable. -mkdir -m a-r -p a/unreadable - +mkdir -m a-r -p a/unreadable || framework_failure_ # This would fail for e.g., coreutils-5.93. rm -rf inacc || fail=1 @@ -35,4 +34,28 @@ test -d inacc && fail=1 rm -rf a || fail=1 test -d a && fail=1 +# Ensure that using rm -d removes an unreadable empty directory. +mkdir -m a-r unreadable2 || framework_failure_ +mkdir -m0 inacc2 || framework_failure_ + +# These would fail for coreutils-9.1 and prior. +rm -d unreadable2 || fail=1 +test -d unreadable2 && fail=1 +rm -d inacc2 || fail=1 +test -d inacc2 && fail=1 + +# Test the interactive code paths that are new with 9.2: +mkdir -m0 inacc2 || framework_failure_ + +echo n | rm ---presume-input-tty -di inacc2 > out 2>&1 || fail=1 +# decline: ensure it was not deleted, and the prompt was as expected. +printf "rm: attempt removal of inaccessible directory 'inacc2'? " > exp +test -d inacc2 || fail=1 +compare exp out || fail=1 + +echo y | rm ---presume-input-tty -di inacc2 > out 2>&1 || fail=1 +# accept: ensure it **was** deleted, and the prompt was as expected. +test -d inacc2 && fail=1 +compare exp out || fail=1 + Exit $fail -- cgit v1.2.1