]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Split off mail_cache_header_add_field_locked()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 20 Mar 2020 14:29:17 +0000 (16:29 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 08:57:20 +0000 (08:57 +0000)
src/lib-index/mail-cache-transaction.c

index 1f70b17eca169e7b28369f18f0a9cf8560178f8c..54980bc3e0eefc05406d4ecc2272c8e03efa58c0 100644 (file)
@@ -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)