bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#12339: Bug: rm -fr . doesn't dir depth first deletion yet it is docu


From: Linda Walsh
Subject: 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
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666


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));





reply via email to

[Prev in Thread] Current Thread [Next in Thread]