cydir-sync.c revision b7ad29db8cf906da01ee4626730868881087950b
e59faf65ce864fe95dc00f5d52b8323cdbd0608aTimo Sirainen/* Copyright (c) 2007-2008 Dovecot authors, see the included COPYING file */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen offsetof(struct mail_index_header, uid_validity),
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
66ecc94150cbce23aad3240135e0782e0a74d479Timo Sirainen const char *dir;
ef5fb27361cc5e15766e85e28355750ff04b13c9Timo Sirainen dir = mailbox_list_get_path(mbox->storage->storage.list,
6bc0f424bcdb9119d8159874cf98adfa53eefd9aTimo Sirainencydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen ctx->path_dir_prefix_len = str_len(ctx->path);
ad850190d946d34966a56838cfdb216e021b5b5fTimo Sirainen mail_index_lookup_uid(ctx->sync_view, seq1, &uid);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen str_truncate(ctx->path, ctx->path_dir_prefix_len);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen mail_storage_set_critical(&ctx->mbox->storage->storage,
8aacc9e7c84f8376822823ec98c2f551d4919b2eTimo Sirainen /* continue anyway */
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void cydir_sync_index(struct cydir_sync_context *ctx)
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen /* mark the newly seen messages as recent */
d9fdacd5fb3e07997e5c389739d2054f0c8441d8Timo Sirainen if (mail_index_lookup_seq_range(ctx->sync_view, hdr->first_recent_uid,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen index_mailbox_set_recent_seq(&ctx->mbox->ibox, ctx->sync_view,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen while (mail_index_sync_next(ctx->index_sync_ctx, &sync_rec)) {
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (!mail_index_lookup_seq_range(ctx->sync_view,
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen /* already expunged, nothing to do. */
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen /* don't care */
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainen /* FIXME: should be bother calling sync_notify()? */
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainenint cydir_sync_begin(struct cydir_mailbox *mbox,
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen struct cydir_sync_context **ctx_r, bool force)
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY;
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainen sync_flags |= MAIL_INDEX_SYNC_FLAG_REQUIRE_CHANGES;
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen ret = mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
bc564f1d3d953cf724828322b11ae89e0f59ffc9Timo Sirainenint cydir_sync_finish(struct cydir_sync_context **_ctx, bool success)
69e03a846f6980144aa75bff0590c04852bffbbcTimo Sirainen if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) {
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainenstatic int cydir_sync(struct cydir_mailbox *mbox)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen if (cydir_sync_begin(mbox, &sync_ctx, FALSE) < 0)
abe7afb8f1766fbcef1b9df513109e43d7d16e49Timo Sirainencydir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
fd2f5fbc1f07aa93e2214a28cdf02437fb7d06c8Timo Sirainen struct cydir_mailbox *mbox = (struct cydir_mailbox *)box;
6a19e109ee8c5a6f688da83a86a7f6abeb71abddTimo Sirainen if (index_mailbox_want_full_sync(&mbox->ibox, flags))