]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Make mail_cache_need_reopen() public and require using it explicitly
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 30 Mar 2020 13:24:45 +0000 (16:24 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 15 Apr 2020 09:41:42 +0000 (12:41 +0300)
mail_cache_reopen() no longer implicitly calls it.

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

index 1f3a9cb6f41f9a12e19a54ae5193490e1c40ba31..b42a2cbb40512492a05e5969640bba71c4b61130 100644 (file)
@@ -100,8 +100,10 @@ mail_cache_lookup_offset(struct mail_cache *cache, struct mail_index_view *view,
                        return 0;
                }
 
-               if ((ret = mail_cache_reopen(cache)) <= 0) {
-                       /* error / we already have the latest file open */
+               if (!mail_cache_need_reopen(cache))
+                       return 0;
+               else if ((ret = mail_cache_reopen(cache)) <= 0) {
+                       /* error / corrupted */
                        return ret;
                }
        }
index c9c89856448e94fd666c991835e2ed37f7c1c16d..bdea2c9762a0ae327910a1ce12edb04d19189161 100644 (file)
@@ -258,6 +258,7 @@ int mail_cache_map(struct mail_cache *cache, size_t offset, size_t size,
    (and deleted), -1 if I/O error. */
 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);
 
 /* Notify the decision handling code that field was looked up for seq.
index 9616dd21f3f69f1319148e686de43821478758e8..e7591eaaff944b251160ff3e68630a526f87f201 100644 (file)
@@ -155,7 +155,7 @@ static int mail_cache_try_open(struct mail_cache *cache)
        return 1;
 }
 
-static bool mail_cache_need_reopen(struct mail_cache *cache)
+bool mail_cache_need_reopen(struct mail_cache *cache)
 {
        struct stat st;
 
@@ -198,7 +198,7 @@ static bool mail_cache_need_reopen(struct mail_cache *cache)
        return FALSE;
 }
 
-static int mail_cache_reopen_now(struct mail_cache *cache)
+int mail_cache_reopen(struct mail_cache *cache)
 {
        struct mail_index_view *view;
        const struct mail_index_ext *ext;
@@ -228,17 +228,6 @@ static int mail_cache_reopen_now(struct mail_cache *cache)
        return 1;
 }
 
-int mail_cache_reopen(struct mail_cache *cache)
-{
-       i_assert(!cache->locked);
-
-       if (!mail_cache_need_reopen(cache)) {
-               /* reopening does no good */
-               return 0;
-       }
-       return mail_cache_reopen_now(cache);
-}
-
 static void mail_cache_update_need_compress(struct mail_cache *cache)
 {
        const struct mail_index_cache_optimization_settings *set =
@@ -750,7 +739,7 @@ mail_cache_lock_full(struct mail_cache *cache, bool nonblock)
                        /* locked the latest file */
                        break;
                }
-               if (mail_cache_reopen_now(cache) <= 0) {
+               if (mail_cache_reopen(cache) <= 0) {
                        i_assert(cache->file_lock == NULL);
                        return -1;
                }