changeset 22033:03b5a6dfd3ba

lib-index: Add mail_cache_set_seq_corrupted_reason Marks a seq in cache corrupted, and removes that instead of the whole cache.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Tue, 09 May 2017 14:00:38 +0300
parents c1ea9ded299a
children c68622bea90c
files src/lib-index/mail-cache.c src/lib-index/mail-cache.h
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache.c	Fri May 12 13:35:06 2017 +0300
+++ b/src/lib-index/mail-cache.c	Tue May 09 14:00:38 2017 +0300
@@ -52,6 +52,28 @@
 	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) {
--- a/src/lib-index/mail-cache.h	Fri May 12 13:35:06 2017 +0300
+++ b/src/lib-index/mail-cache.h	Tue May 09 14:00:38 2017 +0300
@@ -139,6 +139,8 @@
 /* "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);