mail-cache-sync-update.c revision bc564f1d3d953cf724828322b11ae89e0f59ffc9
89a126810703c666309310d0f3189e9834d70b5bTimo Sirainen/* Copyright (c) 2004-2007 Dovecot authors, see the included COPYING file */
dd0ba1bab2c1b89c7e063fa45d156fa72b8260d5Timo Sirainenstatic void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen (void)mail_cache_unlock(sync_ctx->view->index->cache);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic struct mail_cache_sync_context *mail_cache_handler_init(void **context)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen *context = i_new(struct mail_cache_sync_context, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic int mail_cache_handler_lock(struct mail_cache_sync_context *ctx,
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen if ((ret = mail_cache_lock(cache, TRUE)) <= 0) {
992a13add4eea0810e4db0f042a595dddf85536aTimo Sirainenstatic int get_cache_file_seq(struct mail_index_view *view,
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen ext = mail_index_view_get_ext(view, view->index->cache->ext_id);
df6478c4cf605bd81b3891c148b84c14eb6c4035Timo Sirainenint mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
e9f2d9104d395bcf54be3f8ba8d9f63aecf0bcbeTimo Sirainen struct mail_cache_sync_context *ctx = *sync_context;
6f73af3a3a6ee900c7e736874587968d76a20bc0Timo Sirainen if (!get_cache_file_seq(sync_ctx->view, &cache_file_seq))
50c4a9739b55370b1d3950d7b3ec2f7cd2ed5f49Timo Sirainen (void)mail_cache_delete(cache, *cache_offset);
6cd02a9525acb9897a65b05bfeee9b8d283e0f74Timo Sirainenint mail_cache_sync_handler(struct mail_index_sync_map_ctx *sync_ctx,
a2ce2eb4c266e2854fd34416ea5cfbe05dfd3971Timo Sirainen struct mail_index_view *view = sync_ctx->view;
a2ce2eb4c266e2854fd34416ea5cfbe05dfd3971Timo Sirainen struct mail_cache *cache = view->index->cache;
a2ce2eb4c266e2854fd34416ea5cfbe05dfd3971Timo Sirainen struct mail_cache_sync_context *ctx = *context;
a2ce2eb4c266e2854fd34416ea5cfbe05dfd3971Timo Sirainen if (cache->file_cache != NULL && !MAIL_CACHE_IS_UNUSABLE(cache)) {
a2ce2eb4c266e2854fd34416ea5cfbe05dfd3971Timo Sirainen /* flush read cache only once per sync */
a2ce2eb4c266e2854fd34416ea5cfbe05dfd3971Timo Sirainen if (!ctx->nfs_read_cache_flushed && cache->index->nfs_flush) {
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen /* don't invalidate anything that's already been invalidated
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen within this sync. */
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen if (*new_cache_offset < ctx->invalidate_highwater) {
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen ctx->invalidate_highwater = *new_cache_offset;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (*old_cache_offset == 0 || *old_cache_offset == *new_cache_offset ||
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen sync_ctx->type == MAIL_INDEX_SYNC_HANDLER_VIEW)
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen mail_transaction_log_view_get_prev_pos(view->log_view,
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen mail_transaction_log_get_mailbox_sync_pos(view->index->log,
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen if (LOG_IS_BEFORE(cur_seq, cur_offset, tail_seq, tail_offset)) {
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen /* already been linked */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen /* we'll need to link the old and new cache records */
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen if (!get_cache_file_seq(view, &cache_file_seq))
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen /* cache has been compressed, don't modify it */
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen if (mail_cache_link(cache, *old_cache_offset, *new_cache_offset) < 0)
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainenvoid mail_cache_sync_lost_handler(struct mail_index *index)
72cbf33ae81fde08384d30c779ff540752d9256cTimo Sirainen mail_index_flush_read_cache(cache->index, cache->filepath,