From: Timo Sirainen Date: Tue, 17 Jun 2008 06:56:28 +0000 (+0300) Subject: mail_index_view_sync_begin() now delays its failures to _commit(). X-Git-Tag: 1.2.alpha1~289 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5a86309a6c58bdeb9921bf2989aaabaaa04a29ab;p=thirdparty%2Fdovecot%2Fcore.git mail_index_view_sync_begin() now delays its failures to _commit(). --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index-view-sync.c b/src/lib-index/mail-index-view-sync.c index 6166dfc0c8..2dbe0abf7d 100644 --- a/src/lib-index/mail-index-view-sync.c +++ b/src/lib-index/mail-index-view-sync.c @@ -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 diff --git a/src/lib-index/mail-index.h b/src/lib-index/mail-index.h index a273ee092a..a204e4b18d 100644 --- a/src/lib-index/mail-index.h +++ b/src/lib-index/mail-index.h @@ -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 diff --git a/src/lib-storage/index/index-sync.c b/src/lib-storage/index/index-sync.c index 71f08ad9bf..b07d9e5f51 100644 --- a/src/lib-storage/index/index-sync.c +++ b/src/lib-storage/index/index-sync.c @@ -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);