cydir-sync.c revision ccc895c0358108d2304239063e940b7d75f364ab
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen/* Copyright (C) 2007 Timo Sirainen */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int cydir_sync_set_uidvalidity(struct cydir_sync_context *ctx)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen trans = mail_index_transaction_begin(ctx->sync_view, FALSE, TRUE);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen offsetof(struct mail_index_header, uid_validity),
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_index_transaction_commit(&trans, &seq, &offset) < 0) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen const char *dir;
ccc895c0358108d2304239063e940b7d75f364abTimo Sirainen dir = mailbox_list_get_path(mbox->storage->storage.list,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenstatic int cydir_sync_index(struct cydir_sync_context *ctx)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen unsigned int prefix_len = 0;
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen /* unlink expunged messages */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen while ((ret = mail_index_sync_next(ctx->index_sync_ctx,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (sync_rec.type != MAIL_INDEX_SYNC_TYPE_EXPUNGE)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_index_lookup_uid_range(ctx->sync_view,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen /* already expunged everything. nothing to do. */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_index_lookup_uid(ctx->sync_view, seq1,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (unlink(str_c(path)) < 0 && errno != ENOENT) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen /* continue anyway */
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenint cydir_sync_begin(struct cydir_mailbox *mbox,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen ret = mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainenint cydir_sync_finish(struct cydir_sync_context **_ctx, bool success)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) {
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_storage_set_index_error(&ctx->mbox->ibox);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mail_index_sync_rollback(&ctx->index_sync_ctx);
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainencydir_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen struct cydir_mailbox *mbox = (struct cydir_mailbox *)box;
c6a57378d3c54988f525f81e19c0c5d132a0770dTimo Sirainen mbox->ibox.sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <=