summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-08-03 09:01:21 -0400
committerJakob Kaivo <jkk@ung.org>2019-08-03 09:01:21 -0400
commit4e511a6470f2d461d32695a5d5a7f874dd088ff8 (patch)
tree9d1f4ff28242455ea0429f5c9611ded959e47305
parent25082b8a3ecae2c1b1a4babe37a56f6c2efc48c1 (diff)
make rm_dir() recursive when pruning
-rw-r--r--rmdir.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/rmdir.c b/rmdir.c
index c4ee227..8ad3f02 100644
--- a/rmdir.c
+++ b/rmdir.c
@@ -32,22 +32,18 @@
static int rm_dir(char *path, int prune)
{
- if (prune) {
- char *working = path;
- while (strcmp(working, ".") && strcmp(working, "/")) {
- if (rmdir(working) != 0) {
- fprintf(stderr, "rmdir: %s: %s\n",
- working, strerror(errno));
- return 1;
- }
- working = dirname(working);
- }
-
- } else if (rmdir(path) != 0) {
+ if (rmdir(path) != 0) {
fprintf(stderr, "rmdir: %s: %s\n", path, strerror(errno));
return 1;
}
+ if (prune) {
+ char *parent = dirname(path);
+ if (strcmp(parent, ".") && strcmp(parent, "/")) {
+ return rm_dir(parent, prune);
+ }
+ }
+
return 0;
}