]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Don't leave extra records to dovecot.map.index if mailbox index locking fails.
authorTimo Sirainen <tss@iki.fi>
Wed, 7 Nov 2012 15:05:47 +0000 (17:05 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 7 Nov 2012 15:05:47 +0000 (17:05 +0200)
Fixes errors such as:
Corrupted dbox file /mdbox/storage/m.1 (around offset=2652): EOF reading msg header (got 0/30 bytes)

src/lib-storage/index/dbox-multi/mdbox-save.c

index c6a732ca6b04bace7afa1793abe236cdb6061d48..cf43df2bf24a90f2c7295595403094b90e81ae81 100644 (file)
@@ -296,16 +296,6 @@ int mdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
                mdbox_transaction_save_rollback(_ctx);
                return -1;
        }
-
-       /* assign map UIDs for newly saved messages. they're written to
-          transaction log immediately within this function, but the map
-          is left locked. */
-       if (mdbox_map_append_assign_map_uids(ctx->append_ctx, &first_map_uid,
-                                            &last_map_uid) < 0) {
-               mdbox_transaction_save_rollback(_ctx);
-               return -1;
-       }
-
        /* lock the mailbox after map to avoid deadlocks. if we've noticed
           any corruption, deal with it later, otherwise we won't have
           up-to-date atomic->sync_view */
@@ -318,6 +308,16 @@ int mdbox_transaction_save_commit_pre(struct mail_save_context *_ctx)
                return -1;
        }
 
+       /* assign map UIDs for newly saved messages after we've successfully
+          acquired all the locks. the transaction is now very unlikely to
+          fail. the UIDs are written to the transaction log immediately within
+          this function, but the map is left locked. */
+       if (mdbox_map_append_assign_map_uids(ctx->append_ctx, &first_map_uid,
+                                            &last_map_uid) < 0) {
+               mdbox_transaction_save_rollback(_ctx);
+               return -1;
+       }
+
        /* assign UIDs for new messages */
        hdr = mail_index_get_header(ctx->sync_ctx->sync_view);
        mail_index_append_finish_uids(ctx->ctx.trans, hdr->next_uid,