dovecot: Changed mailbox_list_index_view_init() to return -1 if ...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jul 18 08:20:48 EEST 2007
details: http://hg.dovecot.org/dovecot/rev/8576ce5d7fb4
changeset: 6069:8576ce5d7fb4
user: Timo Sirainen <tss at iki.fi>
date: Wed Jul 18 07:58:21 2007 +0300
description:
Changed mailbox_list_index_view_init() to return -1 if uid_validity doesn't
match between mailbox list index and the view.
diffstat:
4 files changed, 76 insertions(+), 62 deletions(-)
src/lib-index/mailbox-list-index-sync.c | 6 +
src/lib-index/mailbox-list-index.c | 35 +++++------
src/lib-index/mailbox-list-index.h | 9 +-
src/lib-storage/list/index-mailbox-list.c | 88 ++++++++++++++++-------------
diffs (253 lines):
diff -r dc93705c4038 -r 8576ce5d7fb4 src/lib-index/mailbox-list-index-sync.c
--- a/src/lib-index/mailbox-list-index-sync.c Wed Jul 18 07:56:02 2007 +0300
+++ b/src/lib-index/mailbox-list-index-sync.c Wed Jul 18 07:58:21 2007 +0300
@@ -395,8 +395,12 @@ int mailbox_list_index_sync_init(struct
struct mailbox_list_index_sync_ctx **ctx_r)
{
struct mailbox_list_index_sync_ctx *ctx;
+ struct mailbox_list_index_view *view;
pool_t pool;
size_t len;
+
+ if (mailbox_list_index_view_init(index, NULL, &view) < 0)
+ return -1;
/* add separator to end of path if it isn't there */
len = strlen(path);
@@ -409,7 +413,7 @@ int mailbox_list_index_sync_init(struct
ctx = p_new(pool, struct mailbox_list_index_sync_ctx, 1);
ctx->pool = pool;
ctx->index = index;
- ctx->view = mailbox_list_index_view_init(index, NULL);
+ ctx->view = view;
ctx->sync_path = p_strdup(pool, path);
ctx->flags = flags;
diff -r dc93705c4038 -r 8576ce5d7fb4 src/lib-index/mailbox-list-index.c
--- a/src/lib-index/mailbox-list-index.c Wed Jul 18 07:56:02 2007 +0300
+++ b/src/lib-index/mailbox-list-index.c Wed Jul 18 07:58:21 2007 +0300
@@ -132,18 +132,6 @@ mailbox_list_index_check_header(struct m
/* index already marked as corrupted */
return -1;
}
-
- if (hdr->uid_validity != index->mail_index->map->hdr.uid_validity &&
- index->mail_index->map->hdr.uid_validity != 0) {
- mail_index_set_error(index->mail_index,
- "uid_validity changed in file %s: %u -> %u",
- index->filepath,
- index->mail_index->map->hdr.uid_validity,
- hdr->uid_validity);
- mail_index_mark_corrupted(index->mail_index);
- return -1;
- }
-
return 0;
}
@@ -608,16 +596,27 @@ int mailbox_list_index_refresh(struct ma
return mailbox_list_index_open_or_create(index);
}
-struct mailbox_list_index_view *
-mailbox_list_index_view_init(struct mailbox_list_index *index,
- struct mail_index_view *mail_view)
+int mailbox_list_index_view_init(struct mailbox_list_index *index,
+ struct mail_index_view *mail_view,
+ struct mailbox_list_index_view **view_r)
{
struct mailbox_list_index_view *view;
-
- view = i_new(struct mailbox_list_index_view, 1);
+ const struct mail_index_header *hdr;
+
+ hdr = mail_view != NULL ? mail_index_get_header(mail_view) :
+ &index->mail_index->map->hdr;
+ if (hdr->uid_validity != index->hdr->uid_validity) {
+ mail_index_set_error(index->mail_index,
+ "uid_validity mismatch in file %s: %u != %u",
+ index->filepath, index->hdr->uid_validity,
+ hdr->uid_validity);
+ return -1;
+ }
+
+ view = *view_r = i_new(struct mailbox_list_index_view, 1);
view->index = index;
view->mail_view = mail_view;
- return view;
+ return 0;
}
void mailbox_list_index_view_deinit(struct mailbox_list_index_view **_view)
diff -r dc93705c4038 -r 8576ce5d7fb4 src/lib-index/mailbox-list-index.h
--- a/src/lib-index/mailbox-list-index.h Wed Jul 18 07:56:02 2007 +0300
+++ b/src/lib-index/mailbox-list-index.h Wed Jul 18 07:58:21 2007 +0300
@@ -1,6 +1,7 @@
#ifndef __MAILBOX_LIST_INDEX_H
#define __MAILBOX_LIST_INDEX_H
+struct mailbox_list_index_view;
struct mailbox_list_index_sync_ctx;
/* Mailbox list index contains UID <-> mailbox name mapping. It also takes in
@@ -61,10 +62,10 @@ void mailbox_list_index_sync_rollback(st
/* Mailbox list index and mail index must be kept in sync, so lookups and
iterations must know the mail index view. The mail_view can be set to NULL
- to use the latest changes. */
-struct mailbox_list_index_view *
-mailbox_list_index_view_init(struct mailbox_list_index *index,
- struct mail_index_view *mail_view);
+ to use the latest changes. Returns -1 if uidvalidity doesn't match. */
+int mailbox_list_index_view_init(struct mailbox_list_index *index,
+ struct mail_index_view *mail_view,
+ struct mailbox_list_index_view **view_r);
void mailbox_list_index_view_deinit(struct mailbox_list_index_view **view);
/* Get mailbox UID for a given name. Returns 1 if found, 0 if not,
diff -r dc93705c4038 -r 8576ce5d7fb4 src/lib-storage/list/index-mailbox-list.c
--- a/src/lib-storage/list/index-mailbox-list.c Wed Jul 18 07:56:02 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list.c Wed Jul 18 07:58:21 2007 +0300
@@ -172,22 +172,16 @@ index_mailbox_list_sync(struct index_mai
return mailbox_list_index_sync_commit(&sync_ctx);
}
-static struct mailbox_list_iterate_context *
-index_mailbox_list_iter_init(struct mailbox_list *list,
- const char *const *patterns,
- enum mailbox_list_iter_flags flags)
-{
+static bool
+index_mailbox_list_iter_init_try(struct index_mailbox_list_iterate_context *ctx,
+ const char *const *patterns)
+{
+ struct mailbox_list *list = ctx->ctx.list;
+ enum mailbox_list_iter_flags flags = ctx->ctx.flags;
struct index_mailbox_list *ilist = INDEX_LIST_CONTEXT(list);
- struct index_mailbox_list_iterate_context *ctx;
const char *prefix, *cur_prefix, *const *tmp;
enum mailbox_list_iter_flags subs_flags;
- int ret, cur_recurse_level;
-
- ctx = i_new(struct index_mailbox_list_iterate_context, 1);
- ctx->ctx.list = list;
- ctx->ctx.flags = flags;
- ctx->ns_prefix = list->ns->prefix;
- ctx->ns_prefix_len = strlen(ctx->ns_prefix);
+ int cur_recurse_level;
subs_flags = MAILBOX_LIST_ITER_SELECT_SUBSCRIBED |
MAILBOX_LIST_ITER_RETURN_NO_FLAGS;
@@ -195,9 +189,7 @@ index_mailbox_list_iter_init(struct mail
(flags & (subs_flags |
MAILBOX_LIST_ITER_RETURN_CHILDREN)) == subs_flags) {
/* Ignore indexes completely */
- ctx->backend_ctx = ilist->module_ctx.super.
- iter_init(list, patterns, flags);
- return &ctx->ctx;
+ return FALSE;
}
ctx->glob = imap_match_init_multiple(default_pool, patterns, TRUE,
@@ -209,22 +201,18 @@ index_mailbox_list_iter_init(struct mail
if (mailbox_list_subscriptions_fill(&ctx->ctx, ctx->subs_tree,
ctx->glob, FALSE) < 0) {
/* let the backend handle this failure */
- ctx->backend_ctx = ilist->module_ctx.super.
- iter_init(list, patterns, flags);
- return &ctx->ctx;
+ return FALSE;
}
}
/* Refresh index before opening our view */
- if (mail_index_refresh(ilist->mail_index) < 0) {
- ctx->backend_ctx = ilist->module_ctx.super.
- iter_init(list, patterns, flags);
- return &ctx->ctx;
- }
+ if (mail_index_refresh(ilist->mail_index) < 0)
+ return FALSE;
ctx->mail_view = mail_index_view_open(ilist->mail_index);
- ctx->view = mailbox_list_index_view_init(ilist->list_index,
- ctx->mail_view);
+ if (mailbox_list_index_view_init(ilist->list_index,
+ ctx->mail_view, &ctx->view) < 0)
+ return FALSE;
/* FIXME: we could just do multiple lookups for different patterns */
prefix = NULL;
@@ -240,21 +228,18 @@ index_mailbox_list_iter_init(struct mail
prefix = "";
if (index_mailbox_list_is_synced(ctx) <= 0) {
- ret = index_mailbox_list_sync(ctx);
-
+ if (index_mailbox_list_sync(ctx) < 0)
+ return FALSE;
+
+ /* updated, we'll have to reopen views */
mail_index_view_close(&ctx->mail_view);
mailbox_list_index_view_deinit(&ctx->view);
- if (ret < 0) {
- ctx->backend_ctx = ilist->module_ctx.super.
- iter_init(list, patterns, flags);
- return &ctx->ctx;
- }
-
- /* updated, we'll have to reopen views */
ctx->mail_view = mail_index_view_open(ilist->mail_index);
- ctx->view = mailbox_list_index_view_init(ilist->list_index,
- ctx->mail_view);
+ if (mailbox_list_index_view_init(ilist->list_index,
+ ctx->mail_view,
+ &ctx->view) < 0)
+ return FALSE;
}
if ((flags & MAILBOX_LIST_ITER_SELECT_SUBSCRIBED) != 0) {
@@ -272,6 +257,28 @@ index_mailbox_list_iter_init(struct mail
i_strdup_printf("%s%s%c", ctx->ns_prefix, prefix,
list->hierarchy_sep);
}
+ return TRUE;
+}
+
+static struct mailbox_list_iterate_context *
+index_mailbox_list_iter_init(struct mailbox_list *list,
+ const char *const *patterns,
+ enum mailbox_list_iter_flags flags)
+{
+ struct index_mailbox_list *ilist = INDEX_LIST_CONTEXT(list);
+ struct index_mailbox_list_iterate_context *ctx;
+
+ ctx = i_new(struct index_mailbox_list_iterate_context, 1);
+ ctx->ctx.list = list;
+ ctx->ctx.flags = flags;
+ ctx->ns_prefix = list->ns->prefix;
+ ctx->ns_prefix_len = strlen(ctx->ns_prefix);
+
+ if (index_mailbox_list_iter_init_try(ctx, patterns) < 0) {
+ /* no indexing */
+ ctx->backend_ctx = ilist->module_ctx.super.
+ iter_init(list, patterns, flags);
+ }
return &ctx->ctx;
}
@@ -480,8 +487,11 @@ static int index_mailbox_list_open_index
mailbox_list_index_free(&ilist->list_index);
return -1;
}
- ilist->list_sync_view = mailbox_list_index_view_init(ilist->list_index,
- NULL);
+ if (mailbox_list_index_view_init(ilist->list_index, NULL,
+ &ilist->list_sync_view) < 0) {
+ mailbox_list_index_free(&ilist->list_index);
+ return -1;
+ }
return 0;
}
More information about the dovecot-cvs
mailing list