diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-08-03 09:01:21 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-08-03 09:01:21 -0400 |
commit | 4e511a6470f2d461d32695a5d5a7f874dd088ff8 (patch) | |
tree | 9d1f4ff28242455ea0429f5c9611ded959e47305 | |
parent | 25082b8a3ecae2c1b1a4babe37a56f6c2efc48c1 (diff) |
make rm_dir() recursive when pruning
-rw-r--r-- | rmdir.c | 20 |
1 files changed, 8 insertions, 12 deletions
@@ -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; } |