]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Index rebuilding lost fields in cache
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 11 May 2020 14:25:41 +0000 (17:25 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 12 May 2020 17:08:40 +0000 (17:08 +0000)
Regression caused by 5f6d2134690e4b84d38d556e3086668e32f30b50

src/lib-index/mail-cache-purge.c

index b141c4e8bfe585d70ce1c7ea094904c3af837ef9..8ce515f83817e413a9c8e832361e8dceb66256c3 100644 (file)
@@ -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);
                }
        }