]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
doc: enhance diagnostic when rm skips "." or ".." arguments
authorBernhard Voelker <mail@bernhard-voelker.de>
Thu, 21 Nov 2013 00:03:15 +0000 (01:03 +0100)
committerBernhard Voelker <mail@bernhard-voelker.de>
Thu, 21 Nov 2013 10:43:48 +0000 (11:43 +0100)
The error diagnostic
  "rm: cannot remove directory: '.'"
does not give the user a hint for the reason.
Issue a clearer error message.

* src/remove.c (rm_fts): Enhance the error diagnostic in the above
case to emphasize that skipping is done deliberately.
In the corresponding comment, mention that POSIX mandates this
behavior.  Likewise in the subsequent comment for skipping "/".
* doc/coreutils.texi (rm invocation): In the paragraph describing
the above behavior, mention that POSIX mandates it.

doc/coreutils.texi
src/remove.c

index 035f2e67c13b10be92c277a4ed9efb9543b28a5c..64713dc4a8962319b42a8d5816727cfda4efd7e5 100644 (file)
@@ -9281,7 +9281,8 @@ the @option{-f} or @option{--force} option is not given, or the
 If the response is not affirmative, the file is skipped.
 
 Any attempt to remove a file whose last file name component is
-@file{.} or @file{..} is rejected without any prompting.
+@file{.} or @file{..} is rejected without any prompting, as mandated
+by POSIX.
 
 @emph{Warning}: If you use @command{rm} to remove a file, it is usually
 possible to recover the contents of that file.  If you want more assurance
index cdbbec5bbbd6a6fc96c078e63e9b2b918a0f322e..3d386cf24fad80e59623d4dbef0042e29de197a5 100644 (file)
@@ -437,17 +437,21 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x)
       /* Perform checks that can apply only for command-line arguments.  */
       if (ent->fts_level == FTS_ROOTLEVEL)
         {
-          /* If the basename of a command line argument is "." or "..",
+          /* POSIX says:
+             If the basename of a command line argument is "." or "..",
              diagnose it and do nothing more with that argument.  */
           if (dot_or_dotdot (last_component (ent->fts_accpath)))
             {
-              error (0, 0, _("cannot remove directory: %s"),
-                     quote (ent->fts_path));
+              error (0, 0,
+                     _("refusing to remove %s or %s directory: skipping %s"),
+                     quote_n (0, "."), quote_n (1, ".."),
+                     quote_n (2, ent->fts_path));
               fts_skip_tree (fts, ent);
               return RM_ERROR;
             }
 
-          /* If a command line argument resolves to "/" (and --preserve-root
+          /* POSIX also says:
+             If a command line argument resolves to "/" (and --preserve-root
              is in effect -- default) diagnose and skip it.  */
           if (ROOT_DEV_INO_CHECK (x->root_dev_ino, ent->fts_statp))
             {