From: Timo Sirainen Date: Fri, 20 Mar 2020 14:29:17 +0000 (+0200) Subject: lib-index: Split off mail_cache_header_add_field_locked() X-Git-Tag: 2.3.11.2~450 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a9ba6bf3abe0dde223ded61ccbd8c4bb224377ea;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Split off mail_cache_header_add_field_locked() --- diff --git a/src/lib-index/mail-cache-transaction.c b/src/lib-index/mail-cache-transaction.c index 1f70b17eca..54980bc3e0 100644 --- a/src/lib-index/mail-cache-transaction.c +++ b/src/lib-index/mail-cache-transaction.c @@ -644,41 +644,12 @@ static void mail_cache_mark_adding(struct mail_cache *cache, bool set) } } -static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx, - unsigned int field_idx) +static int +mail_cache_header_add_field_locked(struct mail_cache *cache, + unsigned int field_idx) { - struct mail_cache *cache = ctx->cache; int ret; - if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) { - if (cache->file_fields_count <= field_idx) { - cache->file_field_map = - i_realloc_type(cache->file_field_map, - unsigned int, - cache->file_fields_count, - field_idx+1); - cache->file_fields_count = field_idx+1; - } - cache->file_field_map[field_idx] = field_idx; - cache->field_file_map[field_idx] = field_idx; - return 0; - } - - if (mail_cache_transaction_lock(ctx) <= 0) { - if (MAIL_CACHE_IS_UNUSABLE(cache)) - return -1; - - /* if we compressed the cache, the field should be there now. - it's however possible that someone else just compressed it - and we only reopened the cache file. */ - if (cache->field_file_map[field_idx] != (uint32_t)-1) - return 0; - - /* need to add it */ - if (mail_cache_transaction_lock(ctx) <= 0) - return -1; - } - /* re-read header to make sure we don't lose any fields. */ if (mail_cache_header_fields_read(cache) < 0) { (void)mail_cache_unlock(cache); @@ -717,6 +688,42 @@ static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx, return ret; } +static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx, + unsigned int field_idx) +{ + struct mail_cache *cache = ctx->cache; + + if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) { + if (cache->file_fields_count <= field_idx) { + cache->file_field_map = + i_realloc_type(cache->file_field_map, + unsigned int, + cache->file_fields_count, + field_idx+1); + cache->file_fields_count = field_idx+1; + } + cache->file_field_map[field_idx] = field_idx; + cache->field_file_map[field_idx] = field_idx; + return 0; + } + + if (mail_cache_transaction_lock(ctx) <= 0) { + if (MAIL_CACHE_IS_UNUSABLE(cache)) + return -1; + + /* if we compressed the cache, the field should be there now. + it's however possible that someone else just compressed it + and we only reopened the cache file. */ + if (cache->field_file_map[field_idx] != (uint32_t)-1) + return 0; + + /* need to add it */ + if (mail_cache_transaction_lock(ctx) <= 0) + return -1; + } + return mail_cache_header_add_field_locked(cache, field_idx); +} + static int mail_cache_trans_get_file_field(struct mail_cache_transaction_ctx *ctx, unsigned int field_idx, uint32_t *file_field_r)