From 846624bdec0d5deec6cf22071158221391ec5f2d Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Tue, 9 May 2017 14:00:38 +0300 Subject: [PATCH] lib-index: Add mail_cache_set_seq_corrupted_reason Marks a seq in cache corrupted, and removes that instead of the whole cache. --- src/lib-index/mail-cache.c | 22 ++++++++++++++++++++++ src/lib-index/mail-cache.h | 2 ++ 2 files changed, 24 insertions(+) diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 40c989ddea..96e1e17fb3 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -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) { diff --git a/src/lib-index/mail-cache.h b/src/lib-index/mail-cache.h index 227a4b801d..8986afeb5a 100644 --- a/src/lib-index/mail-cache.h +++ b/src/lib-index/mail-cache.h @@ -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);