From: Timo Sirainen Date: Mon, 11 May 2020 14:25:41 +0000 (+0300) Subject: lib-index: Index rebuilding lost fields in cache X-Git-Tag: 2.3.11.2~95 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e23d3b907a5dc49b67a73690fbaad67794b0fd38;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Index rebuilding lost fields in cache Regression caused by 5f6d2134690e4b84d38d556e3086668e32f30b50 --- diff --git a/src/lib-index/mail-cache-purge.c b/src/lib-index/mail-cache-purge.c index b141c4e8bf..8ce515f838 100644 --- a/src/lib-index/mail-cache-purge.c +++ b/src/lib-index/mail-cache-purge.c @@ -203,7 +203,7 @@ static int mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, struct event *event, int fd, const char *reason, uint32_t *file_seq_r, uoff_t *file_size_r, uint32_t *max_uid_r, - ARRAY_TYPE(uint32_t) *ext_offsets) + uint32_t *ext_first_seq_r, ARRAY_TYPE(uint32_t) *ext_offsets) { struct mail_cache_copy_context ctx; struct mail_cache_lookup_iterate_ctx iter; @@ -220,12 +220,13 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, i_assert(reason != NULL); *max_uid_r = 0; + *ext_first_seq_r = 0; /* get the latest info on fields */ if (mail_cache_header_fields_read(cache) < 0) return -1; - view = mail_index_transaction_get_view(trans); + view = mail_index_transaction_open_updated_view(trans); cache_view = mail_cache_view_open(cache, view); output = o_stream_create_fd_file(fd, 0, FALSE); @@ -287,6 +288,7 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, seq = trans->first_new_seq; } + *ext_first_seq_r = seq; i_array_init(ext_offsets, message_count); record_count = 0; for (; seq <= message_count; seq++) { if (mail_index_transaction_is_expunged(trans, seq)) { @@ -342,6 +344,7 @@ mail_cache_copy(struct mail_cache *cache, struct mail_index_transaction *trans, o_stream_nsend(output, &hdr, sizeof(hdr)); mail_cache_view_close(&cache_view); + mail_index_view_close(&view); if (o_stream_finish(output) < 0) { mail_cache_set_syscall_error(cache, "write()"); @@ -372,7 +375,7 @@ mail_cache_purge_write(struct mail_cache *cache, { struct event *event; struct stat st; - uint32_t prev_file_seq, file_seq, old_offset, max_uid; + uint32_t prev_file_seq, file_seq, old_offset, max_uid, ext_first_seq; ARRAY_TYPE(uint32_t) ext_offsets; const uint32_t *offsets; uoff_t prev_file_size, file_size; @@ -393,7 +396,8 @@ mail_cache_purge_write(struct mail_cache *cache, event_add_int(event, "prev_deleted_records", prev_deleted_records); if (mail_cache_copy(cache, trans, event, fd, reason, - &file_seq, &file_size, &max_uid, &ext_offsets) < 0) + &file_seq, &file_size, &max_uid, + &ext_first_seq, &ext_offsets) < 0) return -1; if (fstat(fd, &st) < 0) { @@ -421,7 +425,8 @@ mail_cache_purge_write(struct mail_cache *cache, offsets = array_get(&ext_offsets, &count); for (i = 0; i < count; i++) { if (offsets[i] != 0) { - mail_index_update_ext(trans, i + 1, cache->ext_id, + mail_index_update_ext(trans, ext_first_seq + i, + cache->ext_id, &offsets[i], &old_offset); } }