From: Timo Sirainen Date: Wed, 29 Nov 2017 13:14:02 +0000 (+0200) Subject: lib-storage: Rebuild list index when doing doveadm force-resync X-Git-Tag: 2.3.0.rc1~283 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b42817ce16a8660cbcc4adfc8bccc3db1c6d00c7;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Rebuild list index when doing doveadm force-resync --- diff --git a/src/lib-storage/list/mailbox-list-index-backend.c b/src/lib-storage/list/mailbox-list-index-backend.c index a39a89e5e1..2744a72487 100644 --- a/src/lib-storage/list/mailbox-list-index-backend.c +++ b/src/lib-storage/list/mailbox-list-index-backend.c @@ -584,6 +584,43 @@ static int index_list_mailbox_open(struct mailbox *box) return 0; } +static struct mailbox_sync_context * +index_list_mailbox_sync_init(struct mailbox *box, + enum mailbox_sync_flags flags) +{ + struct index_list_mailbox *ibox = INDEX_LIST_STORAGE_CONTEXT(box); + struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT(box->list); + + if ((flags & MAILBOX_SYNC_FLAG_FORCE_RESYNC) != 0 && + !ilist->force_resynced) { + enum mail_storage_list_index_rebuild_reason reason = + MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_FORCE_RESYNC; + + if (box->storage->v.list_index_rebuild(box->storage, reason) < 0) + ilist->force_resync_failed = TRUE; + /* try to rebuild list index only once - even if it failed */ + ilist->force_resynced = TRUE; + } + return ibox->module_ctx.super.sync_init(box, flags); +} + +static int +index_list_mailbox_sync_deinit(struct mailbox_sync_context *ctx, + struct mailbox_sync_status *status_r) +{ + struct index_list_mailbox *ibox = INDEX_LIST_STORAGE_CONTEXT(ctx->box); + struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT(ctx->box->list); + + if (ibox->module_ctx.super.sync_deinit(ctx, status_r) < 0) + return -1; + if (ilist->force_resync_failed) { + /* fail this only once */ + ilist->force_resync_failed = FALSE; + return -1; + } + return 0; +} + static void index_list_try_delete(struct mailbox_list *_list, const char *name, enum mailbox_list_path_type type) @@ -866,4 +903,6 @@ void mailbox_list_index_backend_init_mailbox(struct mailbox *box, v->update_box = index_list_mailbox_update; v->exists = index_list_mailbox_exists; v->open = index_list_mailbox_open; + v->sync_init = index_list_mailbox_sync_init; + v->sync_deinit = index_list_mailbox_sync_deinit; } diff --git a/src/lib-storage/list/mailbox-list-index.h b/src/lib-storage/list/mailbox-list-index.h index f1ceeee475..3a73e9fff9 100644 --- a/src/lib-storage/list/mailbox-list-index.h +++ b/src/lib-storage/list/mailbox-list-index.h @@ -122,6 +122,8 @@ struct mailbox_list_index { bool handling_corruption:1; bool call_corruption_callback:1; bool rebuild_on_missing_inbox:1; + bool force_resynced:1; + bool force_resync_failed:1; }; struct mailbox_list_index_iterate_context { diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 91d0018eb1..9faca1637c 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -29,6 +29,10 @@ enum mail_storage_list_index_rebuild_reason { this is called in non-error conditions, the callback shouldn't log any errors or warnings if it didn't find any missing mailboxes. */ MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_NO_INBOX, + /* MAILBOX_SYNC_FLAG_FORCE_RESYNC is run. This is called only once + per list, so that doveadm force-resync '*' won't cause it to run for + every mailbox. */ + MAIL_STORAGE_LIST_INDEX_REBUILD_REASON_FORCE_RESYNC, }; struct mail_storage_module_register {