From: Timo Sirainen Date: Thu, 13 Jul 2017 23:11:56 +0000 (+0300) Subject: lib-storage: When index dir rmdir() fails with ENOTEMPTY, retry it for 1 second X-Git-Tag: 2.2.32.rc1~96 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba8eb17a398634b9b7fe7db4cabcada92db44543;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: When index dir rmdir() fails with ENOTEMPTY, retry it for 1 second This helps to avoid leaving those index directories lying around with NFS. Hopefully within the 1 second any existing processes that have been keeping those files open have finished their task. Especially IMAP IDLE will take 0.5 seconds to start syncing indexes and realize that they're deleted. --- diff --git a/src/lib-storage/list/mailbox-list-delete.c b/src/lib-storage/list/mailbox-list-delete.c index 4fa15af984..37f7a19bff 100644 --- a/src/lib-storage/list/mailbox-list-delete.c +++ b/src/lib-storage/list/mailbox-list-delete.c @@ -205,6 +205,9 @@ int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list, mailbox_list_set_critical(list, "unlink(%s) failed: %m", str_c(full_path)); ret = -1; + } else { + /* child directories still exist */ + rmdir_path = FALSE; } } if (errno != 0) { @@ -220,6 +223,17 @@ int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list, return -1; if (rmdir_path) { + unsigned int try_count = 0; + int ret = rmdir(path); + while (ret < 0 && errno == ENOTEMPTY && try_count++ < 10) { + /* We didn't see any child directories, so this is + either a race condition or .nfs* files were left + lying around. In case it's .nfs* files, retry after + waiting a bit. Hopefully all processes keeping those + files open will have closed them by then. */ + usleep(100000); + ret = rmdir(path); + } if (rmdir(path) == 0) unlinked_something = TRUE; else if (errno == ENOENT) {