From: Timo Sirainen Date: Thu, 16 Apr 2020 12:59:24 +0000 (+0300) Subject: lib-index: Fix cache purging when index is being rebuilt X-Git-Tag: 2.3.11.2~339 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5f6d2134690e4b84d38d556e3086668e32f30b50;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fix cache purging when index is being rebuilt All the messages until trans->first_new_seq no longer exist after reset. At best they cause confusion and are ignored. They could also point to high UIDs that the rebuilding removes, causing further corruption errors. --- diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index 32f1f85c42..69cafefe80 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -293,9 +293,15 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, removed. */ first_new_seq = mail_cache_get_first_new_seq(view); message_count = mail_index_view_get_messages_count(view); + if (!trans->reset) + seq = 1; + else { + /* Index is being rebuilt. Ignore old messages. */ + seq = trans->first_new_seq; + } i_array_init(ext_offsets, message_count); record_count = 0; - for (seq = 1; seq <= message_count; seq++) { + for (; seq <= message_count; seq++) { if (mail_index_transaction_is_expunged(trans, seq)) { array_append_zero(ext_offsets); continue;