Attempt rmdir (actually, unlinkat-with-AT_REMOVEDIR) upon any
authorJim Meyering <jim@meyering.net>
Mon, 26 Jun 2006 13:29:48 +0000 (13:29 +0000)
committerJim Meyering <jim@meyering.net>
Mon, 26 Jun 2006 13:29:48 +0000 (13:29 +0000)
fd_to_subdirp failure, not just when errno == EACCES.
* src/remove.c (remove_dir): Use unlinkat-with-AT_REMOVEDIR, not
rmdir, here, even though rmdir may happen to be adequate.

ChangeLog
src/remove.c

index a55c503..22f2f58 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,11 +1,17 @@
 2006-06-26  Jim Meyering  <jim@meyering.net>
 
+       Attempt rmdir (actually, unlinkat-with-AT_REMOVEDIR) upon any
+       fd_to_subdirp failure, not just when errno == EACCES.
+       * src/remove.c (remove_dir): Use unlinkat-with-AT_REMOVEDIR, not
+       rmdir, here, even though rmdir may happen to be adequate.
+
        * NEWS: rm no longer fails to remove an empty, unreadable directory
        * src/remove.c (remove_cwd_entries): If we can't open a directory,
        and the failure is not being ignored, try to remove the directory
        with rmdir (aka unlinkat-with-AT_REMOVEDIR), in case it's empty.
        Problem report and test case from Paul Eggert in
        <http://article.gmane.org/gmane.comp.gnu.core-utils.bugs/7425>.
+
        * tests/rm/empty-inacc: New test, for the above.
 
        Avoid a segfault for wc --files0=- < /dev/null.
index 076ad64..4ee59ce 100644 (file)
@@ -1224,26 +1224,24 @@ remove_dir (int fd_cwd, Dirstack_state *ds, char const *dir,
 
   if (dirp == NULL)
     {
-      int saved_errno = errno;
-      if (errno == EACCES)
+      /* CAUTION: this test and diagnostic are identical to
+        those following the other use of fd_to_subdirp.  */
+      if (errno == ENOENT && x->ignore_missing_files)
        {
-         /* If fd_to_subdirp fails due to permissions, then try to
-            remove DIR via rmdir, in case it's just an empty directory.  */
-         /* This use of rmdir just works, at least in the sole test I
-            have that exercises this code, but it'll soon go, to be
-            replaced by a use of unlinkat-with-AT_REMOVEDIR.  */
-         if (rmdir (dir) == 0)
+         /* With -f, don't report "file not found".  */
+       }
+      else
+       {
+         /* Upon fd_to_subdirp failure, try to remove DIR directly,
+            in case it's just an empty directory.  */
+         int saved_errno = errno;
+         if (unlinkat (fd_cwd, dir, AT_REMOVEDIR) == 0)
            return RM_OK;
 
-         errno = saved_errno;
+         error (0, saved_errno,
+                _("cannot remove %s"), quote (full_filename (dir)));
        }
 
-      /* CAUTION: this test and diagnostic are identical to those
-        following the other use of fd_to_subdirp.  */
-      if (errno != ENOENT || !x->ignore_missing_files)
-       error (0, errno,
-              _("cannot remove %s"), quote (full_filename (dir)));
-
       return RM_ERROR;
     }