From 8260dd2dc45eecba25ee44831f1dd02acc1043f9 Mon Sep 17 00:00:00 2001 From: Przemyslaw Pawelczyk Date: Wed, 2 Sep 2015 02:07:56 +0200 Subject: [PATCH] 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. --- metastore.c | 11 +++++++---- 1 file 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"); } -- 2.11.4.GIT