]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Use mail_cache_compress() where possible
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 27 Mar 2020 10:22:37 +0000 (12:22 +0200)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:42 +0000 (12:41 +0300)
src/lib-index/mail-cache-decisions.c
src/lib-index/mail-cache-transaction.c

index 44aa057fe0698045c4d809ac5d84cd2405886039..5b605afa8e5687b431894863a243a1af6807548b 100644 (file)
@@ -154,18 +154,11 @@ void mail_cache_decision_add(struct mail_cache_view *view, uint32_t seq,
 
 int mail_cache_decisions_copy(struct mail_cache *src, struct mail_cache *dst)
 {
-       struct mail_cache_compress_lock *lock = NULL;
-
        if (mail_cache_open_and_verify(src) < 0)
                return -1;
        if (MAIL_CACHE_IS_UNUSABLE(src))
                return 0; /* no caching decisions */
 
-       struct mail_index_view *dest_view = mail_index_view_open(dst->index);
-       struct mail_index_transaction *itrans =
-               mail_index_transaction_begin(dest_view,
-                                            MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
-
        unsigned int count = 0;
        struct mail_cache_field *fields =
                mail_cache_register_get_list(src, pool_datastack_create(), &count);
@@ -178,11 +171,5 @@ int mail_cache_decisions_copy(struct mail_cache *src, struct mail_cache *dst)
           that the fields are updated even if the cache was already created
           and no compression was done. */
        dst->field_header_write_pending = TRUE;
-       int ret = mail_cache_compress_with_trans(dst, itrans, &lock);
-       if (lock != NULL)
-               mail_cache_compress_unlock(&lock);
-       if (mail_index_transaction_commit(&itrans) < 0)
-               ret = -1;
-       mail_index_view_close(&dest_view);
-       return ret;
+       return mail_cache_compress(dst);
 }
index e3cec007c8e282d0c471bafd5372cc41a988d1c1..5c2301d63ffb88c94411206e2895b9c31ae0f19e 100644 (file)
@@ -179,28 +179,13 @@ static int
 mail_cache_transaction_compress(struct mail_cache_transaction_ctx *ctx)
 {
        struct mail_cache *cache = ctx->cache;
-       struct mail_index_view *view;
-       struct mail_index_transaction *trans;
-       struct mail_cache_compress_lock *lock;
-       int ret;
 
        ctx->tried_compression = TRUE;
 
        cache->need_compress_file_seq =
                MAIL_CACHE_IS_UNUSABLE(cache) ? 0 : cache->hdr->file_seq;
 
-       view = mail_index_view_open(cache->index);
-       trans = mail_index_transaction_begin(view,
-                                       MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
-       if (mail_cache_compress_with_trans(cache, trans, &lock) < 0) {
-               mail_index_transaction_rollback(&trans);
-               ret = -1;
-       } else {
-               ret = mail_index_transaction_commit(&trans);
-               if (lock != NULL)
-                       mail_cache_compress_unlock(&lock);
-       }
-       mail_index_view_close(&view);
+       int ret = mail_cache_compress(cache);
        /* already written cache records must be forgotten, but records in
           memory can still be written to the new cache file */
        mail_cache_transaction_forget_flushed(ctx);