From: Timo Sirainen Date: Tue, 19 Apr 2016 23:23:31 +0000 (+0300) Subject: lib-index: If opening a cache file fails, try again later. X-Git-Tag: 2.3.0.rc1~3992 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f330b7d9e14255fc06bc82908d9bc5a12cccb424;p=thirdparty%2Fdovecot%2Fcore.git lib-index: If opening a cache file fails, try again later. The previous code would never retry opening the cache file within the same session. --- diff --git a/src/lib-index/mail-cache-compress.c b/src/lib-index/mail-cache-compress.c index 1e82fe2ffa..cfc33de57c 100644 --- a/src/lib-index/mail-cache-compress.c +++ b/src/lib-index/mail-cache-compress.c @@ -363,6 +363,7 @@ mail_cache_compress_write(struct mail_cache *cache, } mail_cache_file_close(cache); + cache->opened = TRUE; cache->fd = fd; cache->st_ino = st.st_ino; cache->st_dev = st.st_dev; diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 53b45d58e3..b5b4876b0e 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -77,6 +77,7 @@ void mail_cache_file_close(struct mail_cache *cache) mail_cache_set_syscall_error(cache, "close()"); cache->fd = -1; } + cache->opened = FALSE; } static void mail_cache_init_file_cache(struct mail_cache *cache) @@ -101,14 +102,17 @@ static int mail_cache_try_open(struct mail_cache *cache) { const void *data; + i_assert(!cache->opened); cache->opened = TRUE; if (MAIL_INDEX_IS_IN_MEMORY(cache->index)) return 0; + i_assert(cache->fd == -1); cache->fd = nfs_safe_open(cache->filepath, cache->index->readonly ? O_RDONLY : O_RDWR); if (cache->fd == -1) { + mail_cache_file_close(cache); if (errno == ENOENT) { cache->need_compress_file_seq = 0; return 0; @@ -120,8 +124,10 @@ static int mail_cache_try_open(struct mail_cache *cache) mail_cache_init_file_cache(cache); - if (mail_cache_map(cache, 0, 0, &data) < 0) + if (mail_cache_map(cache, 0, 0, &data) < 0) { + mail_cache_file_close(cache); return -1; + } return 1; }