From: Timo Sirainen Date: Sat, 22 May 2004 01:18:17 +0000 (+0300) Subject: Fix bogus "UID inserted in the middle of mailbox" errors X-Git-Tag: 1.1.alpha1~4072 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a038139a470d2942759b9b86a9852aee7b460996;p=thirdparty%2Fdovecot%2Fcore.git Fix bogus "UID inserted in the middle of mailbox" errors --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/maildir/maildir-sync.c b/src/lib-storage/index/maildir/maildir-sync.c index 0cbd73819b..d8e8c361be 100644 --- a/src/lib-storage/index/maildir/maildir-sync.c +++ b/src/lib-storage/index/maildir/maildir-sync.c @@ -602,15 +602,36 @@ static int maildir_sync_index(struct maildir_sync_context *ctx) } if (rec->uid > uid) { - /* new UID in the middle of the mailbox - - shouldn't happen */ - mail_storage_set_critical(ibox->box.storage, - "Maildir sync: UID inserted in the middle " - "of mailbox (%u > %u, file = %s)", - rec->uid, uid, filename); - mail_index_mark_corrupted(ibox->index); - ret = -1; - break; + /* most likely a race condition: we read the + maildir, then someone else expunged messages and + committed changes to index. so, this message + shouldn't actually exist. check to be sure. + + FIXME: we could avoid this stat() and just mark + this check in the uidlist and check it at next + sync.. */ + struct stat st; + const char *str; + + t_push(); + str = t_strdup_printf("%s/%s", + (uflags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) ? + ctx->new_dir : ctx->cur_dir, filename); + if (stat(str, &st) == 0) { + t_pop(); + mail_storage_set_critical(ibox->box.storage, + "Maildir sync: UID inserted in the " + "middle of mailbox " + "(%u > %u, file = %s)", + rec->uid, uid, filename); + mail_index_mark_corrupted(ibox->index); + ret = -1; + break; + } + t_pop(); + + seq--; + continue; } if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) {