]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Make mail_cache_sync_reset_id() public
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 30 Mar 2020 14:07:14 +0000 (17:07 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:42 +0000 (12:41 +0300)
Also it no longer requires that cache is already locked when being called.

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

index bdea2c9762a0ae327910a1ce12edb04d19189161..066d222fd825dcae0c3018c25dc513d4d5187013 100644 (file)
@@ -260,6 +260,7 @@ int mail_cache_map_all(struct mail_cache *cache);
 void mail_cache_file_close(struct mail_cache *cache);
 bool mail_cache_need_reopen(struct mail_cache *cache);
 int mail_cache_reopen(struct mail_cache *cache);
+int mail_cache_sync_reset_id(struct mail_cache *cache);
 
 /* Notify the decision handling code that field was looked up for seq.
    This should be called even for fields that aren't currently in cache file.
index 92cec89dc933d6c3446646c0b19e8b779969f82f..3efc85f5689fa3b8269c0d85ecacb01a79b2a05d 100644 (file)
@@ -685,10 +685,9 @@ mail_cache_sync_wait_index(struct mail_cache *cache, uint32_t *reset_id_r)
        const char *lock_reason = "cache reset_id sync";
        uint32_t file_seq;
        uoff_t file_offset;
+       bool cache_locked = cache->file_lock != NULL;
        int ret;
 
-       i_assert(cache->file_lock != NULL);
-
        if (cache->index->log_sync_locked)
                return 0;
 
@@ -697,7 +696,8 @@ mail_cache_sync_wait_index(struct mail_cache *cache, uint32_t *reset_id_r)
           unlocks it and only then writes the changes to the index and
           releases the .log lock.) To prevent deadlocks, cache file must be
           locked after the .log, not before. */
-       mail_cache_unlock_file(cache);
+       if (cache_locked)
+               mail_cache_unlock_file(cache);
        if (mail_transaction_log_sync_lock(cache->index->log, lock_reason,
                                           &file_seq, &file_offset) < 0)
                return -1;
@@ -723,12 +723,12 @@ mail_cache_sync_wait_index(struct mail_cache *cache, uint32_t *reset_id_r)
        else
                ret = mail_cache_verify_reset_id(cache, reset_id_r) ? 1 : 0;
        mail_transaction_log_sync_unlock(cache->index->log, lock_reason);
-       if (ret <= 0)
+       if (ret <= 0 || !cache_locked)
                mail_cache_unlock_file(cache);
        return ret;
 }
 
-static int mail_cache_sync_reset_id(struct mail_cache *cache)
+int mail_cache_sync_reset_id(struct mail_cache *cache)
 {
        uint32_t reset_id;
        int ret;