]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mail_index_view_sync_begin() now delays its failures to _commit().
authorTimo Sirainen <tss@iki.fi>
Tue, 17 Jun 2008 06:56:28 +0000 (09:56 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 17 Jun 2008 06:56:28 +0000 (09:56 +0300)
--HG--
branch : HEAD

src/lib-index/mail-index-view-sync.c
src/lib-index/mail-index.h
src/lib-storage/index/index-sync.c

index 6166dfc0c8fbf7bacfe0bbf93f3c46a341ab040b..2dbe0abf7d9692f82e3dcfc730f14c6ea91ecc6b 100644 (file)
@@ -264,9 +264,9 @@ static bool view_sync_have_expunges(struct mail_index_view *view)
        return ret < 0 || have_expunges;
 }
 
-int mail_index_view_sync_begin(struct mail_index_view *view,
-                               enum mail_index_view_sync_flags flags,
-                              struct mail_index_view_sync_ctx **ctx_r)
+struct mail_index_view_sync_ctx *
+mail_index_view_sync_begin(struct mail_index_view *view,
+                          enum mail_index_view_sync_flags flags)
 {
        struct mail_index_view_sync_ctx *ctx;
        struct mail_index_map *map;
@@ -277,13 +277,20 @@ int mail_index_view_sync_begin(struct mail_index_view *view,
        i_assert(!view->syncing);
        i_assert(view->transactions == 0);
 
+       view->syncing = TRUE;
+
+       ctx = i_new(struct mail_index_view_sync_ctx, 1);
+       ctx->view = view;
+       ctx->flags = flags;
+
        quick_sync = (flags & MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT) != 0;
        if (mail_index_view_is_inconsistent(view)) {
                if ((flags & MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT) == 0) {
                        mail_index_set_error(view->index,
                                             "%s view is inconsistent",
                                             view->index->filepath);
-                       return -1;
+                       ctx->failed = TRUE;
+                       return ctx;
                }
                view->inconsistent = FALSE;
        }
@@ -294,20 +301,21 @@ int mail_index_view_sync_begin(struct mail_index_view *view,
                i_array_init(&expunges, 1);
        } else if (sync_expunges) {
                /* get list of all expunges first */
-               if (view_sync_get_expunges(view, &expunges, &expunge_count) < 0)
-                       return -1;
+               if (view_sync_get_expunges(view, &expunges,
+                                          &expunge_count) < 0) {
+                       ctx->failed = TRUE;
+                       return ctx;
+               }
        }
 
        if (view_sync_set_log_view_range(view, sync_expunges, quick_sync,
                                         &reset) < 0) {
                if (array_is_created(&expunges))
                        array_free(&expunges);
-               return -1;
+               ctx->failed = TRUE;
+               return ctx;
        }
 
-       ctx = i_new(struct mail_index_view_sync_ctx, 1);
-       ctx->view = view;
-       ctx->flags = flags;
        ctx->expunges = expunges;
        ctx->finish_min_msg_count = reset || quick_sync ? 0 :
                view->map->hdr.messages_count - expunge_count;
@@ -366,10 +374,7 @@ int mail_index_view_sync_begin(struct mail_index_view *view,
        /* Syncing the view invalidates all previous looked up records.
           Unreference the mappings this view keeps because of them. */
        mail_index_view_unref_maps(view);
-       view->syncing = TRUE;
-
-       *ctx_r = ctx;
-       return 0;
+       return ctx;
 }
 
 static bool
@@ -651,7 +656,8 @@ int mail_index_view_sync_commit(struct mail_index_view_sync_ctx **_ctx,
                view->inconsistent = TRUE;
                ret = -1;
        }
-       mail_index_modseq_sync_end(&ctx->sync_map_ctx.modseq_ctx);
+       if (ctx->sync_map_ctx.view != NULL)
+               mail_index_modseq_sync_end(&ctx->sync_map_ctx.modseq_ctx);
 
        if (ctx->sync_new_map != NULL) {
                mail_index_unmap(&view->map);
@@ -673,7 +679,8 @@ int mail_index_view_sync_commit(struct mail_index_view_sync_ctx **_ctx,
                view->map->hdr.log_file_tail_offset = 0;
        }
 
-       mail_index_sync_map_deinit(&ctx->sync_map_ctx);
+       if (ctx->sync_map_ctx.view != NULL)
+               mail_index_sync_map_deinit(&ctx->sync_map_ctx);
        mail_index_view_sync_clean_log_syncs(ctx->view);
 
 #ifdef DEBUG
index a273ee092a9ec9b04ce6afbb821d2d531e1b1d88..a204e4b18d02a2778faf60e292e1884f38f3a991 100644 (file)
@@ -306,9 +306,9 @@ int mail_index_fsck(struct mail_index *index);
 /* Synchronize changes in view. You have to go through all records, or view
    will be marked inconsistent. Only sync_mask type records are
    synchronized. */
-int mail_index_view_sync_begin(struct mail_index_view *view,
-                               enum mail_index_view_sync_flags flags,
-                              struct mail_index_view_sync_ctx **ctx_r);
+struct mail_index_view_sync_ctx *
+mail_index_view_sync_begin(struct mail_index_view *view,
+                          enum mail_index_view_sync_flags flags);
 bool mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
                               struct mail_index_view_sync_rec *sync_rec);
 void
index 71f08ad9bf245373855e852bf1f9120f94152ffa..b07d9e5f5137bea04ad74a7b0d7f1cc7b849400b 100644 (file)
@@ -182,13 +182,7 @@ index_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
                        mail_index_view_get_messages_count(ibox->view);
        }
 
-       if (mail_index_view_sync_begin(ibox->view, sync_flags,
-                                      &ctx->sync_ctx) < 0) {
-               mail_storage_set_index_error(ibox);
-               ctx->failed = TRUE;
-               return &ctx->ctx;
-       }
-
+       ctx->sync_ctx = mail_index_view_sync_begin(ibox->view, sync_flags);
        if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) == 0) {
                mail_index_view_sync_get_expunges(ctx->sync_ctx,
                                                  &ctx->expunges);