summaryrefslogtreecommitdiffstats
path: root/toolbox/rm.c
diff options
context:
space:
mode:
Diffstat (limited to 'toolbox/rm.c')
-rw-r--r--toolbox/rm.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/toolbox/rm.c b/toolbox/rm.c
index 3a24bec..957b586 100644
--- a/toolbox/rm.c
+++ b/toolbox/rm.c
@@ -45,8 +45,10 @@ static int unlink_recursive(const char* name, int flags)
continue;
sprintf(dn, "%s/%s", name, de->d_name);
if (unlink_recursive(dn, flags) < 0) {
- fail = 1;
- break;
+ if (!(flags & OPT_FORCE)) {
+ fail = 1;
+ break;
+ }
}
errno = 0;
}
@@ -71,6 +73,7 @@ int rm_main(int argc, char *argv[])
int ret;
int i, c;
int flags = 0;
+ int something_failed = 0;
if (argc < 2)
return usage();
@@ -103,17 +106,21 @@ int rm_main(int argc, char *argv[])
ret = unlink_recursive(argv[i], flags);
} else {
ret = unlink(argv[i]);
- if (errno == ENOENT && (flags & OPT_FORCE)) {
- return 0;
+ if (ret < 0 && errno == ENOENT && (flags & OPT_FORCE)) {
+ continue;
}
}
if (ret < 0) {
fprintf(stderr, "rm failed for %s, %s\n", argv[i], strerror(errno));
- return -1;
+ if (!(flags & OPT_FORCE)) {
+ return -1;
+ } else {
+ something_failed = 1;
+ }
}
}
- return 0;
+ return something_failed;
}