]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Move mailbox_list_index_view_open() to mailbox-list-index.c
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 9 Jul 2019 14:16:33 +0000 (17:16 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 10 Jul 2019 06:48:24 +0000 (06:48 +0000)
It's a bit more appropriate location for it now that it's not strictly used
by only the STATUS caching code.

src/lib-storage/list/mailbox-list-index-status.c
src/lib-storage/list/mailbox-list-index.c

index 266996d920a62f9f0693e2ec2c633573e26a92a1..7a0a0a6ed52c163cad09e377d21306269a1d2aa8 100644 (file)
@@ -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)
index c70b1e08078bb966fe3b8dea87a9e11e6a66564b..300ff3cc2e2e3a1dc32637d36fffb7c4f0051765 100644 (file)
@@ -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);