# HG changeset patch # User Timo Sirainen # Date 1190459587 -10800 # Node ID 5ad7a36ca8c3079dbaf960956bfe6cce64446e7e # Parent b5e6543b4385df25cffedc0ec269d4546afde43e mail_cache_transaction_commit()/rollback() API is now public and takes a ** pointer. Don't break if transaction is committed/rollbacked multiple times for a cache view. diff -r b5e6543b4385 -r 5ad7a36ca8c3 src/lib-index/mail-cache-private.h --- a/src/lib-index/mail-cache-private.h Sat Sep 22 13:55:36 2007 +0300 +++ b/src/lib-index/mail-cache-private.h Sat Sep 22 14:13:07 2007 +0300 @@ -230,9 +230,6 @@ int mail_cache_lookup_iter_next(struct mail_cache_lookup_iterate_ctx *ctx, struct mail_cache_iterate_field *field_r); -int mail_cache_transaction_commit(struct mail_cache_transaction_ctx *ctx); -void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx *ctx); - int mail_cache_map(struct mail_cache *cache, size_t offset, size_t size); void mail_cache_file_close(struct mail_cache *cache); int mail_cache_reopen(struct mail_cache *cache); diff -r b5e6543b4385 -r 5ad7a36ca8c3 src/lib-index/mail-cache-transaction.c --- a/src/lib-index/mail-cache-transaction.c Sat Sep 22 13:55:36 2007 +0300 +++ b/src/lib-index/mail-cache-transaction.c Sat Sep 22 14:13:07 2007 +0300 @@ -89,11 +89,18 @@ ctx->changes = FALSE; } -static void mail_cache_transaction_free(struct mail_cache_transaction_ctx *ctx) +static void +mail_cache_transaction_free(struct mail_cache_transaction_ctx **_ctx) { + struct mail_cache_transaction_ctx *ctx = *_ctx; + + *_ctx = NULL; + + ctx->trans->cache_trans_ctx = NULL; ctx->view->transaction = NULL; ctx->view->trans_seq1 = ctx->view->trans_seq2 = 0; + mail_index_view_close(&ctx->view->trans_view); if (ctx->cache_data != NULL) buffer_free(&ctx->cache_data); if (array_is_created(&ctx->cache_data_seq)) @@ -603,18 +610,19 @@ ctx->changes = TRUE; } -int mail_cache_transaction_commit(struct mail_cache_transaction_ctx *ctx) +int mail_cache_transaction_commit(struct mail_cache_transaction_ctx **_ctx) { + struct mail_cache_transaction_ctx *ctx = *_ctx; struct mail_cache *cache = ctx->cache; int ret = 0; if (!ctx->changes || MAIL_CACHE_IS_UNUSABLE(cache)) { - mail_cache_transaction_free(ctx); + mail_cache_transaction_free(_ctx); return 0; } if (mail_cache_transaction_lock(ctx) <= 0) { - mail_cache_transaction_rollback(ctx); + mail_cache_transaction_rollback(_ctx); return -1; } @@ -631,12 +639,13 @@ if (mail_cache_unlock(cache) < 0) ret = -1; - mail_cache_transaction_free(ctx); + mail_cache_transaction_free(_ctx); return ret; } -void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx *ctx) +void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx **_ctx) { + struct mail_cache_transaction_ctx *ctx = *_ctx; struct mail_cache *cache = ctx->cache; const struct mail_cache_reservation *reservations; unsigned int count; @@ -660,7 +669,7 @@ } } - mail_cache_transaction_free(ctx); + mail_cache_transaction_free(_ctx); } static int diff -r b5e6543b4385 -r 5ad7a36ca8c3 src/lib-index/mail-cache.c --- a/src/lib-index/mail-cache.c Sat Sep 22 13:55:36 2007 +0300 +++ b/src/lib-index/mail-cache.c Sat Sep 22 14:13:07 2007 +0300 @@ -612,12 +612,11 @@ void mail_cache_view_close(struct mail_cache_view *view) { + i_assert(view->trans_view == NULL); + if (view->cache->field_header_write_pending) (void)mail_cache_header_fields_update(view->cache); - if (view->trans_view != NULL) - mail_index_view_close(&view->trans_view); - array_free(&view->looping_offsets); buffer_free(&view->cached_exists_buf); i_free(view); diff -r b5e6543b4385 -r 5ad7a36ca8c3 src/lib-index/mail-cache.h --- a/src/lib-index/mail-cache.h Sat Sep 22 13:55:36 2007 +0300 +++ b/src/lib-index/mail-cache.h Sat Sep 22 14:13:07 2007 +0300 @@ -71,6 +71,9 @@ mail_cache_get_transaction(struct mail_cache_view *view, struct mail_index_transaction *t); +int mail_cache_transaction_commit(struct mail_cache_transaction_ctx **ctx); +void mail_cache_transaction_rollback(struct mail_cache_transaction_ctx **ctx); + /* Add new field to given record. Updates are not allowed. Fixed size fields must be exactly the expected size. */ void mail_cache_add(struct mail_cache_transaction_ctx *ctx, uint32_t seq, diff -r b5e6543b4385 -r 5ad7a36ca8c3 src/lib-index/mail-index-transaction.c --- a/src/lib-index/mail-index-transaction.c Sat Sep 22 13:55:36 2007 +0300 +++ b/src/lib-index/mail-index-transaction.c Sat Sep 22 14:13:07 2007 +0300 @@ -81,10 +81,8 @@ memset(t->pre_hdr_mask, 0, sizeof(t->pre_hdr_mask)); memset(t->post_hdr_mask, 0, sizeof(t->post_hdr_mask)); - if (t->cache_trans_ctx != NULL) { - mail_cache_transaction_rollback(t->cache_trans_ctx); - t->cache_trans_ctx = NULL; - } + if (t->cache_trans_ctx != NULL) + mail_cache_transaction_rollback(&t->cache_trans_ctx); t->appends_nonsorted = FALSE; t->pre_hdr_changed = FALSE; @@ -534,10 +532,8 @@ i_assert(t->first_new_seq > mail_index_view_get_messages_count(t->view)); - if (t->cache_trans_ctx != NULL) { - mail_cache_transaction_commit(t->cache_trans_ctx); - t->cache_trans_ctx = NULL; - } + if (t->cache_trans_ctx != NULL) + mail_cache_transaction_commit(&t->cache_trans_ctx); if (array_is_created(&t->appends)) { mail_index_transaction_sort_appends(t); @@ -557,10 +553,8 @@ static void mail_index_transaction_rollback_v(struct mail_index_transaction *t) { - if (t->cache_trans_ctx != NULL) { - mail_cache_transaction_rollback(t->cache_trans_ctx); - t->cache_trans_ctx = NULL; - } + if (t->cache_trans_ctx != NULL) + mail_cache_transaction_rollback(&t->cache_trans_ctx); mail_index_transaction_unref(&t); }