From: Timo Sirainen Date: Tue, 9 Jul 2019 14:16:33 +0000 (+0300) Subject: lib-storage: Move mailbox_list_index_view_open() to mailbox-list-index.c X-Git-Tag: 2.3.9~384 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e71724d674316a0ab559abb1c99cea0d701144aa;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Move mailbox_list_index_view_open() to mailbox-list-index.c It's a bit more appropriate location for it now that it's not strictly used by only the STATUS caching code. --- diff --git a/src/lib-storage/list/mailbox-list-index-status.c b/src/lib-storage/list/mailbox-list-index-status.c index 266996d920..7a0a0a6ed5 100644 --- a/src/lib-storage/list/mailbox-list-index-status.c +++ b/src/lib-storage/list/mailbox-list-index-status.c @@ -27,64 +27,6 @@ struct index_list_changes { struct index_list_storage_module index_list_storage_module = MODULE_CONTEXT_INIT(&mail_storage_module_register); -int mailbox_list_index_view_open(struct mailbox *box, bool require_refreshed, - struct mail_index_view **view_r, - uint32_t *seq_r) -{ - struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT_REQUIRE(box->list); - struct mailbox_list_index_node *node; - struct mail_index_view *view; - uint32_t seq; - int ret; - - if (MAILBOX_IS_NEVER_IN_INDEX(box) && require_refreshed) { - /* Optimization: Caller wants the list index to be up-to-date - for this mailbox, but this mailbox isn't updated to the list - index at all. */ - return 0; - } - if (mailbox_list_index_refresh(box->list) < 0) { - mail_storage_copy_list_error(box->storage, box->list); - return -1; - } - - node = mailbox_list_index_lookup(box->list, box->name); - if (node == NULL) { - /* mailbox not found */ - return 0; - } - - view = mail_index_view_open(ilist->index); - if (mailbox_list_index_need_refresh(ilist, view)) { - /* mailbox_list_index_refresh_later() was called. - Can't trust the index's contents. */ - ret = 1; - } else if (!mail_index_lookup_seq(view, node->uid, &seq)) { - /* our in-memory tree is out of sync */ - ret = 1; - } else if (!require_refreshed) { - /* this operation doesn't need the index to be up-to-date */ - ret = 0; - } else T_BEGIN { - ret = box->v.list_index_has_changed == NULL ? 0 : - box->v.list_index_has_changed(box, view, seq, FALSE); - } T_END; - - if (ret != 0) { - /* error / mailbox has changed. we'll need to sync it. */ - if (ret < 0) - mailbox_list_index_refresh_later(box->list); - else - ilist->index_last_check_changed = TRUE; - mail_index_view_close(&view); - return ret < 0 ? -1 : 0; - } - - *view_r = view; - *seq_r = seq; - return 1; -} - static int index_list_exists(struct mailbox *box, bool auto_boxes, enum mailbox_existence *existence_r) diff --git a/src/lib-storage/list/mailbox-list-index.c b/src/lib-storage/list/mailbox-list-index.c index c70b1e0807..300ff3cc2e 100644 --- a/src/lib-storage/list/mailbox-list-index.c +++ b/src/lib-storage/list/mailbox-list-index.c @@ -657,6 +657,64 @@ int mailbox_list_index_set_uncorrupted(struct mailbox_list *list) return mailbox_list_index_sync_end(&sync_ctx, TRUE); } +int mailbox_list_index_view_open(struct mailbox *box, bool require_refreshed, + struct mail_index_view **view_r, + uint32_t *seq_r) +{ + struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT_REQUIRE(box->list); + struct mailbox_list_index_node *node; + struct mail_index_view *view; + uint32_t seq; + int ret; + + if (MAILBOX_IS_NEVER_IN_INDEX(box) && require_refreshed) { + /* Optimization: Caller wants the list index to be up-to-date + for this mailbox, but this mailbox isn't updated to the list + index at all. */ + return 0; + } + if (mailbox_list_index_refresh(box->list) < 0) { + mail_storage_copy_list_error(box->storage, box->list); + return -1; + } + + node = mailbox_list_index_lookup(box->list, box->name); + if (node == NULL) { + /* mailbox not found */ + return 0; + } + + view = mail_index_view_open(ilist->index); + if (mailbox_list_index_need_refresh(ilist, view)) { + /* mailbox_list_index_refresh_later() was called. + Can't trust the index's contents. */ + ret = 1; + } else if (!mail_index_lookup_seq(view, node->uid, &seq)) { + /* our in-memory tree is out of sync */ + ret = 1; + } else if (!require_refreshed) { + /* this operation doesn't need the index to be up-to-date */ + ret = 0; + } else T_BEGIN { + ret = box->v.list_index_has_changed == NULL ? 0 : + box->v.list_index_has_changed(box, view, seq, FALSE); + } T_END; + + if (ret != 0) { + /* error / mailbox has changed. we'll need to sync it. */ + if (ret < 0) + mailbox_list_index_refresh_later(box->list); + else + ilist->index_last_check_changed = TRUE; + mail_index_view_close(&view); + return ret < 0 ? -1 : 0; + } + + *view_r = view; + *seq_r = seq; + return 1; +} + static void mailbox_list_index_deinit(struct mailbox_list *list) { struct mailbox_list_index *ilist = INDEX_LIST_CONTEXT_REQUIRE(list);