static void dbox_sync_index_copy_cache(struct dbox_sync_rebuild_context *ctx, struct mail_index_view *view, uint32_t old_seq, uint32_t new_seq) { struct mail_index_map *map; const void *data; uint32_t reset_id; bool expunged; if (ctx->cache_ext_id == (uint32_t)-1) return; mail_index_lookup_ext_full(view, old_seq, ctx->cache_ext_id, &map, &data, &expunged); if (expunged) return; if (!mail_index_ext_get_reset_id(view, map, ctx->cache_ext_id, &reset_id) || reset_id == 0) return; if (!ctx->cache_used) { /* set reset id */ ctx->cache_used = TRUE; ctx->cache_reset_id = reset_id; mail_index_ext_reset(ctx->trans, ctx->cache_ext_id, ctx->cache_reset_id, TRUE); } if (ctx->cache_reset_id == reset_id) { mail_index_update_ext(ctx->trans, new_seq, ctx->cache_ext_id, data, NULL); } }
void mbox_list_index_update_sync(struct mailbox *box, struct mail_index_transaction *trans, uint32_t seq) { struct mbox_mailbox *mbox = (struct mbox_mailbox *)box; struct mail_index_view *list_view; const struct mbox_index_header *mhdr = &mbox->mbox_hdr; const struct mbox_list_index_record *old_rec; struct mbox_list_index_record new_rec; const void *data; uint32_t ext_id; bool expunged; index_storage_list_index_update_sync(box, trans, seq); /* get the current record */ list_view = mail_index_transaction_get_view(trans); ext_id = mbox_list_get_ext_id(mbox, list_view); mail_index_lookup_ext(list_view, seq, ext_id, &data, &expunged); if (expunged) return; old_rec = data; memset(&new_rec, 0, sizeof(new_rec)); new_rec.mtime = mhdr->sync_mtime; new_rec.size = mhdr->sync_size & 0xffffffffU; if (old_rec == NULL || memcmp(old_rec, &new_rec, sizeof(*old_rec)) != 0) mail_index_update_ext(trans, seq, ext_id, &new_rec, NULL); }
static int index_list_update(struct index_mailbox_list *ilist, struct mailbox *box, struct mail_index_view *view, uint32_t seq, const struct mailbox_status *status) { struct index_list_mailbox *ibox = INDEX_LIST_STORAGE_CONTEXT(box); struct mail_index_transaction *trans; struct mail_index_transaction_commit_result result; const void *data; const uint32_t *counter_p; uint32_t *ext_id_p; unsigned int i; bool expunged; int ret = 0; trans = mail_index_transaction_begin(view, MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL); /* update counters */ for (i = 0; index_list_map[i].name != NULL; i++) { ext_id_p = PTR_OFFSET(ilist, index_list_map[i].eid_offset); mail_index_lookup_ext(view, seq, *ext_id_p, &data, &expunged); if (expunged) { ret = -1; break; } counter_p = CONST_PTR_OFFSET(status, index_list_map[i].status_offset); if (data == NULL || *(const uint32_t *)data != *counter_p) { mail_index_update_ext(trans, seq, *ext_id_p, counter_p, NULL); } } if (box->v.list_index_update_sync(box, trans, seq) < 0) ret = -1; if (ret < 0) { mail_index_transaction_rollback(&trans); return -1; } if (mail_index_transaction_commit_full(&trans, &result) < 0) return -1; ibox->log_seq = result.log_file_seq; ibox->log_offset = result.log_file_offset; return 0; }