Skip to content

Commit

Permalink
lib-index: If opening a cache file fails, try again later.
Browse files Browse the repository at this point in the history
The previous code would never retry opening the cache file within the same
session.
  • Loading branch information
sirainen authored and GitLab committed Apr 20, 2016
1 parent 46d91e9 commit f330b7d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib-index/mail-cache-compress.c
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/lib-index/mail-cache.c
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down

0 comments on commit f330b7d

Please sign in to comment.