aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/rm.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-09-05 04:19:37 -0500
committerRob Landley <rob@landley.net>2013-09-05 04:19:37 -0500
commit829497311b541b63e08aa17768c8e67e95b73638 (patch)
treed1add5fe4434ec6a5a251ded6a750010854e0424 /toys/posix/rm.c
parent1f747f730f4bd94e8266f4cb763fc0eb1cbf1948 (diff)
downloadtoybox-829497311b541b63e08aa17768c8e67e95b73638.tar.gz
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.
Diffstat (limited to 'toys/posix/rm.c')
-rw-r--r--toys/posix/rm.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/toys/posix/rm.c b/toys/posix/rm.c
index 7954daec..d9ad60d4 100644
--- a/toys/posix/rm.c
+++ b/toys/posix/rm.c
@@ -47,10 +47,9 @@ static int do_rm(struct dirtree *try)
// 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 @@ static int do_rm(struct dirtree *try)
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;