Mercurial > dovecot > core-2.2
changeset 2593:6c03f22b2489 HEAD
If cache file was recreated the buffered transaction changes were written
into the new file which may have corrupted it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 11 Sep 2004 15:08:37 +0300 |
parents | 5edda9783458 |
children | 96f454eb52c2 |
files | src/lib-index/mail-cache-transaction.c |
diffstat | 1 files changed, 38 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache-transaction.c Sat Sep 11 15:07:01 2004 +0300 +++ b/src/lib-index/mail-cache-transaction.c Sat Sep 11 15:08:37 2004 +0300 @@ -16,6 +16,8 @@ struct mail_cache_view *view; struct mail_index_transaction *trans; + uint32_t cache_file_seq; + buffer_t *cache_data, *cache_data_seq; uint32_t prev_seq; size_t prev_pos; @@ -55,6 +57,25 @@ return ctx; } +static void mail_cache_transaction_reset(struct mail_cache_transaction_ctx *ctx) +{ + ctx->cache_file_seq = ctx->cache->hdr->file_seq; + + if (ctx->cache_data) + buffer_set_used_size(ctx->cache_data, 0); + if (ctx->cache_data_seq) + buffer_set_used_size(ctx->cache_data_seq, 0); + ctx->prev_seq = 0; + ctx->prev_pos = 0; + + buffer_set_used_size(ctx->reservations, 0); + ctx->reserved_space_offset = 0; + ctx->reserved_space = 0; + ctx->last_grow_size = 0; + + ctx->changes = FALSE; +} + static void mail_cache_transaction_free(struct mail_cache_transaction_ctx *ctx) { ctx->view->transaction = NULL; @@ -68,6 +89,18 @@ i_free(ctx); } +static int mail_cache_transaction_lock(struct mail_cache_transaction_ctx *ctx) +{ + int ret; + + if ((ret = mail_cache_lock(ctx->cache)) <= 0) + return ret; + + if (ctx->cache_file_seq != ctx->cache->hdr->file_seq) + mail_cache_transaction_reset(ctx); + return 1; +} + static int mail_cache_grow_file(struct mail_cache *cache, size_t size) { struct stat st; @@ -263,7 +296,7 @@ return; if (!locked) { - if (mail_cache_lock(ctx->cache) <= 0) + if (mail_cache_transaction_lock(ctx) <= 0) return; } @@ -289,7 +322,7 @@ if (min_size > ctx->reserved_space) { if (!locked) { - if (mail_cache_lock(ctx->cache) <= 0) + if (mail_cache_transaction_lock(ctx) <= 0) return -1; } ret = mail_cache_transaction_reserve_more(ctx, max_size, @@ -455,7 +488,7 @@ return 0; } - if (mail_cache_lock(cache) <= 0) { + if (mail_cache_transaction_lock(ctx) <= 0) { mail_cache_transaction_rollback(ctx); return -1; } @@ -489,7 +522,7 @@ if ((ctx->reserved_space > 0 || size > 0) && !MAIL_CACHE_IS_UNUSABLE(cache)) { - if (mail_cache_lock(cache) > 0) { + if (mail_cache_transaction_lock(ctx) > 0) { mail_cache_transaction_free_space(ctx); if (size > 0) { @@ -521,7 +554,7 @@ uint32_t offset, hdr_offset; int ret = 0; - if (mail_cache_lock(cache) <= 0) + if (mail_cache_transaction_lock(ctx) <= 0) return -1; /* re-read header to make sure we don't lose any fields. */