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

From: Linda Walsh <[email-masked]>
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));