Mercurial > dovecot > original-hg > dovecot-1.2
changeset 5074:fc4722a1687b HEAD
If we can't find the mail from dirty mbox even after syncing, fail with
error instead of looping forever.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 25 Jan 2007 11:39:08 +0200 |
parents | 5b4678cd68dc |
children | d0b50249e816 |
files | src/lib-storage/index/mbox/mbox-mail.c |
diffstat | 1 files changed, 42 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-mail.c Thu Jan 25 11:38:23 2007 +0200 +++ b/src/lib-storage/index/mbox/mbox-mail.c Thu Jan 25 11:39:08 2007 +0200 @@ -36,54 +36,60 @@ (struct mbox_transaction_context *)mail->trans; struct mbox_mailbox *mbox = (struct mbox_mailbox *)mail->ibox; enum mbox_sync_flags sync_flags = 0; - int ret; + int ret, try; bool deleted; if (mail->mail.mail.expunged) return 0; -__again: - if (mbox->mbox_lock_type == F_UNLCK) { - sync_flags |= MBOX_SYNC_LOCK_READING; - if (mbox_sync(mbox, sync_flags) < 0) + for (try = 0; try < 2; try++) { + if (mbox->mbox_lock_type == F_UNLCK) { + sync_flags |= MBOX_SYNC_LOCK_READING; + if (mbox_sync(mbox, sync_flags) < 0) + return -1; + + /* refresh index file after mbox has been locked to + make sure we get only up-to-date mbox offsets. */ + if (mail_index_refresh(mbox->ibox.index) < 0) { + mail_storage_set_index_error(&mbox->ibox); + return -1; + } + + i_assert(mbox->mbox_lock_type != F_UNLCK); + t->mbox_lock_id = mbox->mbox_lock_id; + } else if ((sync_flags & MBOX_SYNC_FORCE_SYNC) != 0) { + /* dirty offsets are broken and mbox is write-locked. + sync it to update offsets. */ + if (mbox_sync(mbox, sync_flags) < 0) + return -1; + } + + if (mbox_file_open_stream(mbox) < 0) return -1; - /* refresh index file after mbox has been locked to make - sure we get only up-to-date mbox offsets. */ - if (mail_index_refresh(mbox->ibox.index) < 0) { - mail_storage_set_index_error(&mbox->ibox); + ret = mbox_file_seek(mbox, mail->trans->trans_view, + mail->mail.mail.seq, &deleted); + if (ret > 0) { + /* success */ + break; + } + if (ret < 0) { + if (deleted) { + mail->mail.mail.expunged = TRUE; + return 0; + } return -1; } - i_assert(mbox->mbox_lock_type != F_UNLCK); - t->mbox_lock_id = mbox->mbox_lock_id; - } else if ((sync_flags & MBOX_SYNC_FORCE_SYNC) != 0) { - /* dirty offsets are broken and mbox is write-locked. - sync it to update offsets. */ - if (mbox_sync(mbox, sync_flags) < 0) - return -1; + /* we'll need to re-sync it completely */ + mbox_prepare_resync(mail); + sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC; } - - if (mbox_file_open_stream(mbox) < 0) - return -1; - - ret = mbox_file_seek(mbox, mail->trans->trans_view, - mail->mail.mail.seq, &deleted); - if (ret < 0) { - if (deleted) { - mail->mail.mail.expunged = TRUE; - return 0; - } - return -1; + if (ret == 0) { + mail_storage_set_critical(STORAGE(mbox->storage), + "Losing sync for mail uid=%u in mbox file %s", + mail->mail.mail.uid, mbox->path); } - - if (ret == 0) { - /* we'll need to re-sync it completely */ - mbox_prepare_resync(mail); - sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC; - goto __again; - } - return 1; }