]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_cache_expunge_count
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 9 May 2017 11:29:04 +0000 (14:29 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 11 May 2017 08:17:54 +0000 (11:17 +0300)
It can be called to correctly handle cache counters
when records are removed.

src/lib-index/mail-cache-private.h
src/lib-index/mail-cache-sync-update.c

index 72500d05a5ad2b36fb00d8067574d461f6192993..3406c3e736627cd27af125bb1131b1f5e3c5d8b3 100644 (file)
@@ -229,6 +229,7 @@ int mail_cache_header_fields_update(struct mail_cache *cache);
 void mail_cache_header_fields_get(struct mail_cache *cache, buffer_t *dest);
 int mail_cache_header_fields_get_next_offset(struct mail_cache *cache,
                                             uint32_t *offset_r);
+void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count);
 
 uint32_t mail_cache_lookup_cur_offset(struct mail_index_view *view,
                                      uint32_t seq, uint32_t *reset_id_r);
index 603c7d157210dac0c894dd376fe97fde8feea2f0..fb93dbdd73b1c7b94417eae451e0f6aa551d9e75 100644 (file)
@@ -8,6 +8,19 @@ struct mail_cache_sync_context {
        unsigned expunge_count;
 };
 
+void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count)
+{
+       if (mail_cache_lock(cache) > 0) {
+               cache->hdr_copy.deleted_record_count += count;
+               if (cache->hdr_copy.record_count >= count)
+                       cache->hdr_copy.record_count -= count;
+               else
+                        cache->hdr_copy.record_count = 0;
+               cache->hdr_modified = TRUE;
+               (void)mail_cache_unlock(cache);
+       }
+}
+
 static struct mail_cache_sync_context *mail_cache_handler_init(void **context)
 {
        struct mail_cache_sync_context *ctx;
@@ -29,18 +42,8 @@ static void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
        if (ctx == NULL)
                return;
 
-       if (mail_cache_lock(cache) > 0) {
-               /* update the record counts in the cache file's header. these
-                  are used to figure out when a cache file should be
-                  recreated and the old data dropped. */
-               cache->hdr_copy.deleted_record_count += ctx->expunge_count;
-               if (cache->hdr_copy.record_count >= ctx->expunge_count)
-                       cache->hdr_copy.record_count -= ctx->expunge_count;
-               else
-                       cache->hdr_copy.record_count = 0;
-               cache->hdr_modified = TRUE;
-               (void)mail_cache_unlock(cache);
-       }
+       mail_cache_expunge_count(cache, ctx->expunge_count);
+
        i_free(ctx);
 }