]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
rm: disallow --n alias for --no-preserve-root
authorPádraig Brady <P@draigBrady.com>
Tue, 4 Oct 2016 12:43:32 +0000 (13:43 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 4 Oct 2016 22:35:59 +0000 (23:35 +0100)
* src/rm.c (main): Ensure the full --no-preserve-root
option is specified, rather than allowing --n etc.
* tests/rm/r-root.sh: Add a test case.
* NEWS: Mention the change in behavior.

Improved by Jim Meyering.
Fixes http://bugs.gnu.org/24604

NEWS
src/rm.c
tests/rm/r-root.sh

diff --git a/NEWS b/NEWS
index c3554d0fedb54d370aef9f57318564605c47ed90..e68de05a2300c19d9aeb394351865620237760db 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -52,6 +52,8 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Changes in behavior
 
+  rm no longer accepts shortened variants of the --no-preserve-root option.
+
   seq no longer accepts 0 value as increment, and now also rejects NaN
   values for any argument.
 
@@ -81,8 +83,8 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** New Features
 
-   date now accepts the --debug option, to annotate the parsed date string,
-   display timezone information, and warn about potential misuse.
+  date now accepts the --debug option, to annotate the parsed date string,
+  display timezone information, and warn about potential misuse.
 
 
 * Noteworthy changes in release 8.25 (2016-01-20) [stable]
index 13a5714c332af8c36425802406d97a3ba86055e3..2c54405f7bbed832813b7f58e73d4b3b99f87857 100644 (file)
--- a/src/rm.c
+++ b/src/rm.c
@@ -287,6 +287,9 @@ main (int argc, char **argv)
           break;
 
         case NO_PRESERVE_ROOT:
+          if (! STREQ (argv[optind - 1], "--no-preserve-root"))
+            error (EXIT_FAILURE, 0,
+                   _("you may not abbreviate the --no-preserve-root option"));
           preserve_root = false;
           break;
 
index b98db141be98b222d4ab2277d1b166c9e959d62d..3b7837fe021926a065319868cbdc572f92ccc2cb 100755 (executable)
@@ -210,6 +210,15 @@ for opts in           \
   test $fail = 1 && { cat out; cat err; Exit $fail; }
 done
 
+#-------------------------------------------------------------------------------
+# Exercise with --no-preserve to ensure shortened equivalent is not allowed.
+cat <<EOD > exp_opt || framework_failure_
+rm: you may not abbreviate the --no-preserve-root option
+EOD
+returns_ 1 exercise_rm_r_root --no-preserve / || fail=1
+compare exp_opt err || fail=1
+test -f x && fail=1
+
 #-------------------------------------------------------------------------------
 # Exercise "rm -r file1 / file2".
 # Expect a non-Zero exit status representing failure to remove "/",