From: Timo Sirainen Date: Mon, 30 Mar 2020 13:24:45 +0000 (+0300) Subject: lib-index: Make mail_cache_need_reopen() public and require using it explicitly X-Git-Tag: 2.3.11.2~402 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fc53ba41b2e8a115b08df75f8bef973831fe4fae;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Make mail_cache_need_reopen() public and require using it explicitly mail_cache_reopen() no longer implicitly calls it. --- diff --git a/src/lib-index/mail-cache-lookup.c b/src/lib-index/mail-cache-lookup.c index 1f3a9cb6f4..b42a2cbb40 100644 --- a/src/lib-index/mail-cache-lookup.c +++ b/src/lib-index/mail-cache-lookup.c @@ -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; } } diff --git a/src/lib-index/mail-cache-private.h b/src/lib-index/mail-cache-private.h index c9c8985644..bdea2c9762 100644 --- a/src/lib-index/mail-cache-private.h +++ b/src/lib-index/mail-cache-private.h @@ -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. diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 9616dd21f3..e7591eaaff 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -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; }