]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Move fields from struct mail_index to struct mail_index_error
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 20 Jan 2021 16:07:33 +0000 (18:07 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 3 May 2021 13:01:05 +0000 (13:01 +0000)
This clarifies which are error related fields.

nodiskspace isn't actually currently used for anything, but it seems
potentially useful in the future.

src/lib-index/mail-index-private.h
src/lib-index/mail-index-strmap.c
src/lib-index/mail-index.c

index 67ee71ce777b29ef1baae1af64116288cd45653e..e5f8c7ed68fe906797b32f242e5837aac4018324 100644 (file)
@@ -172,6 +172,15 @@ struct mail_index_settings {
        void *ext_hdr_init_data;
 };
 
+struct mail_index_error {
+       /* Human-readable error text */
+       char *text;
+
+       /* Error happened because there's no disk space, i.e. syscall failed
+          with ENOSPC or EDQUOT. */
+       bool nodiskspace:1;
+};
+
 struct mail_index {
        char *dir, *prefix;
        struct event *event;
@@ -232,8 +241,9 @@ struct mail_index {
        /* Module-specific contexts. */
        ARRAY(union mail_index_module_context *) module_contexts;
 
-       char *error;
-       bool nodiskspace:1;
+       /* Last error returned by mail_index_get_error_message().
+          Cleared by mail_index_reset_error(). */
+       struct mail_index_error last_error;
 
        bool index_delete_requested:1; /* next sync sets it deleted */
        bool index_deleted:1; /* no changes allowed anymore */
index 7d74f978e6e5c2b6622a96c893d44f7d24acd4ea..0210c22a991229d3d1ba0be726a3c1cb1af9e9a6 100644 (file)
@@ -125,7 +125,7 @@ mail_index_strmap_set_syscall_error(struct mail_index_strmap *strmap,
        i_assert(function != NULL);
 
        if (ENOSPACE(errno)) {
-               strmap->index->nodiskspace = TRUE;
+               strmap->index->last_error.nodiskspace = TRUE;
                if ((strmap->index->flags &
                     MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) == 0)
                        return;
index 1a0d730074d32eaddc828db041c63112c3545501..026e5790a1323675ad04f7a68c464ed19cef73f3 100644 (file)
@@ -113,7 +113,7 @@ void mail_index_free(struct mail_index **_index)
        i_free(index->set.cache_dir);
        i_free(index->set.ext_hdr_init_data);
        i_free(index->set.gid_origin);
-       i_free(index->error);
+       i_free(index->last_error.text);
        i_free(index->dir);
        i_free(index->prefix);
        i_free(index->need_recreate);
@@ -888,16 +888,16 @@ void mail_index_set_error(struct mail_index *index, const char *fmt, ...)
 {
        va_list va;
 
-       i_free(index->error);
+       i_free(index->last_error.text);
 
        if (fmt == NULL)
-               index->error = NULL;
+               index->last_error.text = NULL;
        else {
                va_start(va, fmt);
-               index->error = i_strdup_vprintf(fmt, va);
+               index->last_error.text = i_strdup_vprintf(fmt, va);
                va_end(va);
 
-               e_error(index->event, "%s", index->error);
+               e_error(index->event, "%s", index->last_error.text);
        }
 }
 
@@ -905,8 +905,8 @@ void mail_index_set_error_nolog(struct mail_index *index, const char *str)
 {
        i_assert(str != NULL);
 
-       char *old_error = index->error;
-       index->error = i_strdup(str);
+       char *old_error = index->last_error.text;
+       index->last_error.text = i_strdup(str);
        i_free(old_error);
 }
 
@@ -1089,7 +1089,7 @@ void mail_index_file_set_syscall_error(struct mail_index *index,
        }
 
        if (ENOSPACE(errno)) {
-               index->nodiskspace = TRUE;
+               index->last_error.nodiskspace = TRUE;
                if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) == 0)
                        return;
        }
@@ -1112,15 +1112,11 @@ void mail_index_file_set_syscall_error(struct mail_index *index,
 
 const char *mail_index_get_error_message(struct mail_index *index)
 {
-       return index->error;
+       return index->last_error.text;
 }
 
 void mail_index_reset_error(struct mail_index *index)
 {
-       if (index->error != NULL) {
-               i_free(index->error);
-               index->error = NULL;
-       }
-
-       index->nodiskspace = FALSE;
+       i_free(index->last_error.text);
+       i_zero(&index->last_error);
 }