]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
rm: with -I, prompt before deleting a write protected file
authorSergio Durigan Junior <sergiodj@sergiodj.net>
Wed, 25 Sep 2013 10:02:08 +0000 (11:02 +0100)
committerPádraig Brady <P@draigBrady.com>
Thu, 26 Sep 2013 10:25:05 +0000 (11:25 +0100)
This regression was introduced in commit v6.7-71-g0928c24

* src/rm.c (main): Make the -I option behave like --interactive=once.
* tests/rm/interactive-once.sh: Add cases for single and multiple files.
* NEWS: Mention the bug fix.
Fixes http://bugs.gnu.org/9308

NEWS
src/rm.c
tests/rm/interactive-once.sh

diff --git a/NEWS b/NEWS
index c152bbf0530217b1c5a89d6a0ea53e08baf61c56..39dd3d6b5d22b5042e3ba781fcf0d4489f02c22f 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   print approximately 2*N bytes of extraneous padding.
   [Bug introduced in coreutils-7.0]
 
+  rm -I now prompts for confirmation before removing a write protected file.
+  [Bug introduced in coreutils-6.8]
+
   tail --retry -f now waits for the files specified to appear.  Before, tail
   would immediately exit when such a file is inaccessible during the initial
   open.
index 4b87c12e8996dc4a7ef3d7c2aa6e0988d4614332..7a51eefe9a576db79d209557b5219cc6bdf75677 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -244,7 +244,7 @@ main (int argc, char **argv)
           break;
 
         case 'I':
-          x.interactive = RMI_NEVER;
+          x.interactive = RMI_SOMETIMES;
           x.ignore_missing_files = false;
           prompt_once = true;
           break;
index dcda5b84827d5dbc93063209e1c061557b1a17c3..1064c0851f429c34d258972c479c7cf56472ba87 100755 (executable)
@@ -35,6 +35,15 @@ rm -I file1-* < in-n >> out 2>> err || fail=1
 echo . >> err || fail=1
 test -f file1-1 && fail=1
 
+if ls /dev/stdin >/dev/null 2>&1; then
+  echo 'one file, read only, answer no' >> err || fail=1
+  touch file1-1 || framework_failure_
+  chmod a-w file1-1 || framework_failure_
+  rm ---presume-input-tty -I file1-* < in-n >> out 2>> err || fail=1
+  echo . >> err || fail=1
+  test -f file1-1 || fail=1
+fi
+
 echo 'three files, no recursion' >> err || fail=1
 rm -I file2-* < in-n >> out 2>> err || fail=1
 echo . >> err || fail=1
@@ -58,6 +67,19 @@ test -f file3-2 && fail=1
 test -f file3-3 && fail=1
 test -f file3-4 && fail=1
 
+if ls /dev/stdin >/dev/null 2>&1; then
+  echo 'four files, no recursion, 1 read only, answer yes no' >> err || fail=1
+  touch file3-1 file3-2 file3-3 file3-4 || framework_failure_
+  echo non_empty > file3-4 || framework_failure_ # to shorten diagnostic
+  chmod a-w file3-4 || framework_failure_
+  cat in-y in-n | rm ---presume-input-tty -I file3-* >> out 2>> err || fail=1
+  echo . >> err || fail=1
+  test -f file3-1 && fail=1
+  test -f file3-2 && fail=1
+  test -f file3-3 && fail=1
+  test -f file3-4 || fail=1
+fi
+
 echo 'one file, recursion, answer no' >> err || fail=1
 rm -I -R dir1-* < in-n >> out 2>> err || fail=1
 echo . >> err || fail=1
@@ -85,12 +107,16 @@ EOF
 cat <<\EOF > experr || fail=1
 one file, no recursion
 .
+one file, read only, answer no
+rm: remove write-protected regular empty file 'file1-1'? .
 three files, no recursion
 .
 four files, no recursion, answer no
 rm: remove 4 arguments? .
 four files, no recursion, answer yes
 rm: remove 4 arguments? .
+four files, no recursion, 1 read only, answer yes no
+rm: remove 4 arguments? rm: remove write-protected regular file 'file3-4'? .
 one file, recursion, answer no
 rm: remove 1 argument recursively? .
 one file, recursion, answer yes