]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: When rebuilding storage, fsck the map index first to make sure it's valid.
authorTimo Sirainen <tss@iki.fi>
Tue, 27 Nov 2012 08:39:26 +0000 (10:39 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 27 Nov 2012 08:39:26 +0000 (10:39 +0200)
This fixes assert-crash when the map index contained records with UIDs in
wrong order.

src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c

index 7bc20a7b001370778ab3010460ccd7ffd6ef096b..3682b35e6f9e4a7261a43b0722110147cf3286c1 100644 (file)
@@ -243,7 +243,8 @@ int mdbox_map_open_or_create(struct mdbox_map *map)
 int mdbox_map_refresh(struct mdbox_map *map)
 {
        struct mail_index_view_sync_ctx *ctx;
-       bool delayed_expunges;
+       bool delayed_expunges, fscked;
+       int ret = 0;
 
        /* some open files may have read partially written mails. now that
           map syncing makes the new mails visible, we need to make sure the
@@ -262,14 +263,15 @@ int mdbox_map_refresh(struct mdbox_map *map)
 
        ctx = mail_index_view_sync_begin(map->view,
                                MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT);
-       if (mail_index_reset_fscked(map->view->index))
-               mdbox_storage_set_corrupted(map->storage);
+       fscked = mail_index_reset_fscked(map->view->index);
        if (mail_index_view_sync_commit(&ctx, &delayed_expunges) < 0) {
                mail_storage_set_internal_error(MAP_STORAGE(map));
                mail_index_reset_error(map->index);
-               return -1;
+               ret = -1;
        }
-       return 0;
+       if (fscked)
+               mdbox_storage_set_corrupted(map->storage);
+       return ret;
 }
 
 static void
index f6c0903d88a3739ddac4eb19a906790b5132e0cd..c285750e06197edc08335e7f2cb5b281526af190 100644 (file)
@@ -836,6 +836,12 @@ static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx)
        if (mdbox_map_atomic_lock(ctx->atomic) < 0)
                return -1;
 
+       /* fsck the map just in case its UIDs are broken */
+       if (mail_index_fsck(ctx->storage->map->index) < 0) {
+               mail_storage_set_internal_error(&ctx->storage->storage.storage);
+               return -1;
+       }
+
        /* get old map header */
        mail_index_get_header_ext(ctx->atomic->sync_view,
                                  ctx->storage->map->map_ext_id,