From: Timo Sirainen Date: Wed, 20 Jan 2021 16:07:33 +0000 (+0200) Subject: lib-index: Move fields from struct mail_index to struct mail_index_error X-Git-Tag: 2.3.16~294 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15aea21ba8dd0477137cfb67971c8661730bd343;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Move fields from struct mail_index to struct mail_index_error This clarifies which are error related fields. nodiskspace isn't actually currently used for anything, but it seems potentially useful in the future. --- diff --git a/src/lib-index/mail-index-private.h b/src/lib-index/mail-index-private.h index 67ee71ce77..e5f8c7ed68 100644 --- a/src/lib-index/mail-index-private.h +++ b/src/lib-index/mail-index-private.h @@ -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 */ diff --git a/src/lib-index/mail-index-strmap.c b/src/lib-index/mail-index-strmap.c index 7d74f978e6..0210c22a99 100644 --- a/src/lib-index/mail-index-strmap.c +++ b/src/lib-index/mail-index-strmap.c @@ -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; diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index 1a0d730074..026e5790a1 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -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); }