Skip to content

Commit

Permalink
lib-index: Add mail_cache_set_seq_corrupted_reason
Browse files Browse the repository at this point in the history
Marks a seq in cache corrupted, and removes
that instead of the whole cache.
  • Loading branch information
cmouse authored and villesavolainen committed May 15, 2017
1 parent b9d46a5 commit 12fef03
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/lib-index/mail-cache.c
Expand Up @@ -52,6 +52,28 @@ void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
va_end(va);
}

void mail_cache_set_seq_corrupted_reason(struct mail_cache_view *cache_view,
uint32_t seq, const char *reason)
{
uint32_t empty = 0;
struct mail_cache *cache = cache_view->cache;
struct mail_index_view *view = cache_view->view;

mail_index_set_error(cache->index,
"Corrupted record in index cache file %s: %s",
cache->filepath, reason);

/* drop cache pointer */
struct mail_index_transaction *t =
mail_index_transaction_begin(view, MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
mail_index_update_ext(t, seq, cache->ext_id, &empty, NULL);

if (mail_index_transaction_commit(&t) < 0)
mail_cache_reset(cache);
else
mail_cache_expunge_count(cache, 1);
}

void mail_cache_file_close(struct mail_cache *cache)
{
if (cache->mmap_base != NULL) {
Expand Down
2 changes: 2 additions & 0 deletions src/lib-index/mail-cache.h
Expand Up @@ -139,6 +139,8 @@ int mail_cache_lookup_headers(struct mail_cache_view *view, string_t *dest,
/* "Error in index cache file %s: ...". */
void mail_cache_set_corrupted(struct mail_cache *cache, const char *fmt, ...)
ATTR_FORMAT(2, 3);
void mail_cache_set_seq_corrupted_reason(struct mail_cache_view *cache_view,
uint32_t seq, const char *reason);
/* Delete the cache file. */
void mail_cache_reset(struct mail_cache *cache);

Expand Down

0 comments on commit 12fef03

Please sign in to comment.