]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_cache_set_seq_corrupted_reason
authorAki Tuomi <aki.tuomi@dovecot.fi>
Tue, 9 May 2017 11:00:38 +0000 (14:00 +0300)
committerGitLab <gitlab@git.dovecot.net>
Thu, 11 May 2017 08:17:54 +0000 (11:17 +0300)
Marks a seq in cache corrupted, and removes
that instead of the whole cache.

src/lib-index/mail-cache.c
src/lib-index/mail-cache.h

index 40c989ddea87c216488ac544c5265090110b8449..96e1e17fb3cc6b552fad2313e7bc573b65439818 100644 (file)
@@ -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) {
index 227a4b801dc7b9904feb1e90e47769a7745aaf55..8986afeb5a685db4c55be67051772abf068ad4d8 100644 (file)
@@ -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);