summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPrzemyslaw Pawelczyk <przemoc@gmail.com>2015-09-02 02:07:56 +0200
committerPrzemyslaw Pawelczyk <przemoc@gmail.com>2015-09-02 02:07:56 +0200
commit8260dd2dc45eecba25ee44831f1dd02acc1043f9 (patch)
tree310be6595822149ce47caf71221371a8c1e9de52
parentddcca5bce8b09c6a8263a2affa392e11df7f91c8 (diff)
metastore.c: Improve removing empty dirs not present in metadata.
Update extradirs list after successful rmdir(), so already removed directory won't be provided to rmdir() again.
-rw-r--r--metastore.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/metastore.c b/metastore.c
index 240dd3c..e607af4 100644
--- a/metastore.c
+++ b/metastore.c
@@ -340,7 +340,7 @@ fixup_emptydirs(struct metahash *real, struct metahash *stored)
static void
fixup_newemptydirs(void)
{
- struct metaentry *cur;
+ struct metaentry **cur;
int removed_dirs = 1;
if (!extradirs)
@@ -360,12 +360,15 @@ fixup_newemptydirs(void)
while (removed_dirs) {
removed_dirs = 0;
msg(MSG_DEBUG, "\nAttempting to delete empty dirs\n");
- for (cur = extradirs; cur; cur = cur->list) {
- msg(MSG_QUIET, "%s:\tremoving...", cur->path);
- if (rmdir(cur->path)) {
+ for (cur = &extradirs; *cur;) {
+ msg(MSG_QUIET, "%s:\tremoving...", (*cur)->path);
+ if (rmdir((*cur)->path)) {
msg(MSG_QUIET, "failed (%s)\n", strerror(errno));
+ cur = &(*cur)->list;
continue;
}
+ /* No freeing, because OS will do the job at the end. */
+ *cur = (*cur)->list;
removed_dirs++;
msg(MSG_QUIET, "ok\n");
}