changeset 1046:673fe8f927b0 draft

fix rm to handle "mkdir sub/sub && chmod 007 sub/sub && rm -rf sub". Previous version didn't delete it, but exited without error. Neither was right.
author Rob Landley <rob@landley.net>
date Thu, 05 Sep 2013 04:19:37 -0500
parents 00e816559b1f
children d90840f337ea
files toys/posix/rm.c
diffstat 1 files changed, 3 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/toys/posix/rm.c	Wed Sep 04 19:09:00 2013 -0500
+++ b/toys/posix/rm.c	Thu Sep 05 04:19:37 2013 -0500
@@ -47,10 +47,9 @@
 
   // handle directory recursion
   if (dir) {
-
     if (try->data != -1) return DIRTREE_COMEAGAIN;
     using = AT_REMOVEDIR;
-    if (try->symlink) goto nodelete;
+    if (try->symlink) goto skip;
     if (flags & FLAG_i) {
       char *s = dirtree_path(try, 0);
       // This is the section 2(d) prompt. (Yes, posix says to prompt twice.)
@@ -63,9 +62,9 @@
 
 skip:
   if (unlinkat(fd, try->name, using)) {
-    perror_msg("%s", try->name);
+    if (!dir || try->symlink != 2) perror_msg("%s", try->name);
 nodelete:
-    if (try->parent) try->parent->symlink = (char *)1;
+    if (try->parent) try->parent->symlink = (char *)2;
   }
 
   return 0;