From: Timo Sirainen Date: Mon, 14 May 2018 18:31:59 +0000 (+0300) Subject: lib-storage: Add MAILBOX_FLAG_FSCK to fsck index immediately after opening it X-Git-Tag: 2.3.4~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c6a6247939591175f8f8dcdd9286bccc9d901b7a;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Add MAILBOX_FLAG_FSCK to fsck index immediately after opening it This can be used to fix a broken index that is causing mailbox_open() to fail. --- diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index 218b624141..56199fdb4f 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -332,6 +332,12 @@ int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory) return -1; } } + if ((box->flags & MAILBOX_FLAG_FSCK) != 0) { + if (mail_index_fsck(box->index) < 0) { + mailbox_set_index_error(box); + return -1; + } + } box->cache = mail_index_get_cache(box->index); index_cache_register_defaults(box); diff --git a/src/lib-storage/mail-storage.h b/src/lib-storage/mail-storage.h index f863993717..5b7b6fc7fc 100644 --- a/src/lib-storage/mail-storage.h +++ b/src/lib-storage/mail-storage.h @@ -68,7 +68,11 @@ enum mailbox_flags { /* Mailbox is created implicitly if it does not exist. */ MAILBOX_FLAG_AUTO_CREATE = 0x1000, /* Mailbox is subscribed to implicitly when it is created automatically */ - MAILBOX_FLAG_AUTO_SUBSCRIBE = 0x2000 + MAILBOX_FLAG_AUTO_SUBSCRIBE = 0x2000, + /* Run fsck for mailbox index before doing anything else. This may be + useful in fixing index corruption errors that aren't otherwise + detected and that are causing the full mailbox opening to fail. */ + MAILBOX_FLAG_FSCK = 0x4000, }; enum mailbox_feature {