Mercurial > dovecot > core-2.2
changeset 17833:936435377584
lib-storage: Added mailbox_get_index_path() and caching of the index path.
This solves some potential assert-crashes on race conditions when opening a
mailbox while it's being deleted.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 25 Sep 2014 01:13:12 +0300 |
parents | 6d4e7ccb24ea |
children | 65963be31ceb |
files | src/lib-storage/index/index-rebuild.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c |
diffstat | 3 files changed, 23 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-rebuild.c Thu Sep 25 00:42:56 2014 +0300 +++ b/src/lib-storage/index/index-rebuild.c Thu Sep 25 01:13:12 2014 +0300 @@ -167,9 +167,7 @@ mail_cache_reset(box->cache); /* if backup index file exists, try to use it */ - if (mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_INDEX, - &index_dir) <= 0) - i_unreached(); + index_dir = mailbox_get_index_path(box); backup_path = t_strconcat(box->index_prefix, ".backup", NULL); ctx->backup_index = mail_index_alloc(index_dir, backup_path);
--- a/src/lib-storage/mail-storage-private.h Thu Sep 25 00:42:56 2014 +0300 +++ b/src/lib-storage/mail-storage-private.h Thu Sep 25 01:13:12 2014 +0300 @@ -291,6 +291,9 @@ /* Filled lazily when mailbox is opened, use mailbox_get_path() to access it */ const char *_path; + /* Filled lazily when mailbox is opened, use mailbox_get_index_path() + to access it */ + const char *_index_path; /* default vfuncs for new struct mails. */ const struct mail_vfuncs *mail_vfuncs; @@ -646,6 +649,8 @@ The mailbox must already be opened and the caller must know that the storage has mailbox files (i.e. NULL/empty path is never returned). */ const char *mailbox_get_path(struct mailbox *box) ATTR_PURE; +/* Similar to mailbox_get_path() but for MAILBOX_LIST_PATH_TYPE_INDEX. */ +const char *mailbox_get_index_path(struct mailbox *box) ATTR_PURE; /* Wrapper to mailbox_list_get_path() */ int mailbox_get_path_to(struct mailbox *box, enum mailbox_list_path_type type, const char **path_r);
--- a/src/lib-storage/mail-storage.c Thu Sep 25 00:42:56 2014 +0300 +++ b/src/lib-storage/mail-storage.c Thu Sep 25 01:13:12 2014 +0300 @@ -2245,6 +2245,14 @@ *path_r = box->_path; return 1; } + if (type == MAILBOX_LIST_PATH_TYPE_INDEX && box->_index_path != NULL) { + if (box->_index_path[0] == '\0') { + *path_r = NULL; + return 0; + } + *path_r = box->_index_path; + return 1; + } ret = mailbox_list_get_path(box->list, box->name, type, path_r); if (ret < 0) { mail_storage_copy_list_error(box->storage, box->list); @@ -2252,6 +2260,8 @@ } if (type == MAILBOX_LIST_PATH_TYPE_MAILBOX && box->_path == NULL) box->_path = ret == 0 ? "" : p_strdup(box->pool, *path_r); + if (type == MAILBOX_LIST_PATH_TYPE_INDEX && box->_index_path == NULL) + box->_index_path = ret == 0 ? "" : p_strdup(box->pool, *path_r); return ret; } @@ -2262,6 +2272,13 @@ return box->_path; } +const char *mailbox_get_index_path(struct mailbox *box) +{ + i_assert(box->_index_path != NULL); + i_assert(box->_index_path[0] != '\0'); + return box->_index_path; +} + static void mailbox_get_permissions_if_not_set(struct mailbox *box) { if (box->_perm.file_create_mode != 0)