Mercurial > dovecot > core-2.2
changeset 2659:33ad1877ca6d HEAD
Handle UIDVALIDITY changes. When partial syncing, make sure UIDs of new
mails are larger than existing ones. If partial syncing fails, we need to
rollback the transaction.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 23 Sep 2004 13:41:38 +0300 |
parents | fd607e2be4a9 |
children | b1f91349d216 |
files | src/lib-storage/index/mbox/mbox-sync-parse.c src/lib-storage/index/mbox/mbox-sync-private.h src/lib-storage/index/mbox/mbox-sync.c |
diffstat | 3 files changed, 41 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c Thu Sep 23 13:18:08 2004 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync-parse.c Thu Sep 23 13:41:38 2004 +0300 @@ -215,6 +215,7 @@ if (value <= ctx->sync_ctx->prev_msg_uid) { /* broken - UIDs must be growing */ + ctx->uid_broken = TRUE; return FALSE; } ctx->sync_ctx->prev_msg_uid = value;
--- a/src/lib-storage/index/mbox/mbox-sync-private.h Thu Sep 23 13:18:08 2004 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync-private.h Thu Sep 23 13:41:38 2004 +0300 @@ -82,6 +82,7 @@ unsigned int updated:1; unsigned int recent:1; unsigned int seen_received_hdr:1; + unsigned int uid_broken:1; }; struct mbox_sync_context {
--- a/src/lib-storage/index/mbox/mbox-sync.c Thu Sep 23 13:18:08 2004 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync.c Thu Sep 23 13:41:38 2004 +0300 @@ -616,6 +616,7 @@ { struct index_mailbox *ibox = sync_ctx->ibox; uoff_t old_offset; + uint32_t uid; int ret, deleted; if (seq == 0) { @@ -647,6 +648,15 @@ } } + if (seq <= 1) + uid = 0; + else if (mail_index_lookup_uid(sync_ctx->sync_view, seq-1, &uid) < 0) { + mail_storage_set_index_error(ibox); + return -1; + } + + sync_ctx->prev_msg_uid = uid; + /* set to -1, since it's always increased later */ sync_ctx->seq = seq-1; if (sync_ctx->seq == 0 && @@ -722,6 +732,26 @@ while ((ret = mbox_sync_read_next_mail(sync_ctx, mail_ctx)) > 0) { uid = mail_ctx->mail.uid; + if (mail_ctx->seq == 1 && sync_ctx->base_uid_validity != 0 && + sync_ctx->hdr->uid_validity != 0 && + sync_ctx->base_uid_validity != + sync_ctx->hdr->uid_validity) { + mail_storage_set_critical(sync_ctx->ibox->box.storage, + "UIDVALIDITY changed (%u -> %u) " + "in mbox file %s", + sync_ctx->hdr->uid_validity, + sync_ctx->base_uid_validity, + sync_ctx->ibox->path); + mail_index_mark_corrupted(sync_ctx->ibox->index); + return -1; + } + + if (mail_ctx->uid_broken && partial) { + /* UID ordering problems, resync everything to make + sure we get everything right */ + return 0; + } + if (mail_ctx->pseudo) uid = 0; @@ -1033,9 +1063,16 @@ /* partial syncing didn't work, do it again */ mbox_sync_restart(sync_ctx); - if (mbox_sync_loop(sync_ctx, &mail_ctx, - (uint32_t)-1, FALSE) < 0) + + mail_index_transaction_rollback(sync_ctx->t); + sync_ctx->t = mail_index_transaction_begin(sync_ctx->sync_view, + FALSE); + + ret = mbox_sync_loop(sync_ctx, &mail_ctx, (uint32_t)-1, FALSE); + if (ret <= 0) { + i_assert(ret != 0); return -1; + } } if (mbox_sync_handle_eof_updates(sync_ctx, &mail_ctx) < 0)