GNU bug report logs - #12339
Bug: rm -fr . doesn't dir depth first deletion yet it is documented to do so.

Previous Next

Package: coreutils;

Reported by: Linda Walsh <coreutils <at> tlinx.org>

Date: Mon, 3 Sep 2012 00:34:02 UTC

Severity: normal

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #137 received at 12339 <at> debbugs.gnu.org (full text, mbox):

From: Linda Walsh <coreutils <at> tlinx.org>
To: Paul Eggert <eggert <at> cs.ucla.edu>
Cc: Bernhard Voelker <mail <at> bernhard-voelker.de>,
	Jim Meyering <jim <at> meyering.net>,
	"12339 <at> debbugs.gnu.org" <12339 <at> debbugs.gnu.org>
Subject: Re: bug#12339: Bug: rm -fr . doesn't dir depth first deletion yet it
	is	documented to do so.
Date: Wed, 05 Sep 2012 20:25:14 -0700
This doesn't check POSIX_CORRECTLY, but it does fix the reported problem

rm -fr in . removes all files and leaves the dir:

Ishtar:/tmp/ttt> touch one two three
Ishtar:/tmp/ttt> cd ..
Ishtar:/tmp> rm -fr ttt/.
Ishtar:/tmp> ll ttt
total 0

---
Also works cd'd into the dir and doing an "rm -fr ."

I'll be happy to put in the check for POSIX_CORRECTLY if you are amenable...
Note.. am not claiming this is the most efficient way to do it, but it
seemed to be the least impact on code I was new to.

Ishtar:packages/sources/coreutils-8.14> cat coreutils-8.14.remove.c.diff
--- src/remove.c        2011-10-10 00:56:46.000000000 -0700
+++ src/remove.c        2012-09-05 18:23:58.449319142 -0700
@@ -446,6 +446,20 @@
   return RM_ERROR;
 }

+
+static inline bool
+dotdot (char const *file_name)
+{
+  if (file_name[0] == '.' && file_name[1])
+    {
+      char sep = file_name[(file_name[1] == '.') + 1];
+      return (! sep || ISSLASH (sep));
+    }
+  else
+    return false;
+}
+
+
 /* This function is called once for every file system object that fts
    encounters.  fts performs a depth-first traversal.
    A directory is usually processed twice, first with fts_info == FTS_D,
@@ -476,7 +490,7 @@

           /* 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)))
+          if (dotdot (last_component (ent->fts_accpath)))
             {
               error (0, 0, _("cannot remove directory: %s"),
                      quote (ent->fts_path));




This bug report was last modified 6 years and 186 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.