]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Split off mail_cache_sync_reset_id()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 1 Apr 2020 14:00:56 +0000 (17:00 +0300)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 08:57:20 +0000 (08:57 +0000)
src/lib-index/mail-cache.c

index 15f709cf42c1db2e48373557a7a819f2c6369930..2384532fef753535fb044c3893c2488a912c77d2 100644 (file)
@@ -652,15 +652,42 @@ static void mail_cache_unlock_file(struct mail_cache *cache)
        file_unlock(&cache->file_lock);
 }
 
-static int
-mail_cache_lock_full(struct mail_cache *cache, bool nonblock)
+static int mail_cache_sync_reset_id(struct mail_cache *cache)
 {
        const struct mail_index_ext *ext;
-       const void *data;
        struct mail_index_view *iview;
        uint32_t reset_id;
        int i;
 
+       /* now verify that the index reset_id matches the cache's file_seq */
+       for (i = 0; ; i++) {
+               iview = mail_index_view_open(cache->index);
+               ext = mail_index_view_get_ext(iview, cache->ext_id);
+               reset_id = ext == NULL ? 0 : ext->reset_id;
+               mail_index_view_close(&iview);
+
+               if (cache->hdr->file_seq == reset_id)
+                       break;
+               /* mismatch. try refreshing index once. if that doesn't help,
+                  we can't use the cache. */
+               if (i > 0 || cache->index->mapping) {
+                       mail_cache_unlock_file(cache);
+                       return 0;
+               }
+               if (mail_index_refresh(cache->index) < 0) {
+                       mail_cache_unlock_file(cache);
+                       return -1;
+               }
+       }
+       return 1;
+}
+
+static int
+mail_cache_lock_full(struct mail_cache *cache, bool nonblock)
+{
+       const void *data;
+       int ret;
+
        i_assert(!cache->locked);
        /* the only reason why we might be in here while mapping the index is
           if we're coming from mail_cache_expunge_count() while syncing the
@@ -691,26 +718,8 @@ mail_cache_lock_full(struct mail_cache *cache, bool nonblock)
                /* okay, so it was just compressed. try again. */
        }
 
-       /* now verify that the index reset_id matches the cache's file_seq */
-       for (i = 0; ; i++) {
-               iview = mail_index_view_open(cache->index);
-               ext = mail_index_view_get_ext(iview, cache->ext_id);
-               reset_id = ext == NULL ? 0 : ext->reset_id;
-               mail_index_view_close(&iview);
-
-               if (cache->hdr->file_seq == reset_id)
-                       break;
-               /* mismatch. try refreshing index once. if that doesn't help,
-                  we can't use the cache. */
-               if (i > 0 || cache->index->mapping) {
-                       mail_cache_unlock_file(cache);
-                       return 0;
-               }
-               if (mail_index_refresh(cache->index) < 0) {
-                       mail_cache_unlock_file(cache);
-                       return -1;
-               }
-       }
+       if ((ret = mail_cache_sync_reset_id(cache)) <= 0)
+               return ret;
 
        /* successfully locked - make sure our header is up to date */
        cache->locked = TRUE;