dovecot: Handle uid validity changes a bit better.

dovecot at dovecot.org dovecot at dovecot.org
Wed Jul 18 08:20:48 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/461496644c67
changeset: 6072:461496644c67
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jul 18 08:20:43 2007 +0300
description:
Handle uid validity changes a bit better.

diffstat:

3 files changed, 30 insertions(+), 19 deletions(-)
src/lib-index/mailbox-list-index-sync.c   |   27 ++++++++++++++++-----------
src/lib-index/mailbox-list-index.c        |   12 ++++++------
src/lib-storage/list/index-mailbox-list.c |   10 ++++++++--

diffs (98 lines):

diff -r c5919ea0cb33 -r 461496644c67 src/lib-index/mailbox-list-index-sync.c
--- a/src/lib-index/mailbox-list-index-sync.c	Wed Jul 18 08:18:56 2007 +0300
+++ b/src/lib-index/mailbox-list-index-sync.c	Wed Jul 18 08:20:43 2007 +0300
@@ -367,19 +367,24 @@ static int sync_mail_sync_init(struct ma
 
 static int sync_mail_sync_init2(struct mailbox_list_index_sync_ctx *ctx)
 {
-	const struct mail_index_header *hdr;
+	const struct mail_index_header *mail_hdr;
+	uint32_t uid_validity;
 
 	ctx->hdr = *ctx->index->hdr;
-
-	hdr = mail_index_get_header(ctx->mail_view);
-	if (hdr->uid_validity != 0) {
-		if (hdr->uid_validity != ctx->hdr.uid_validity) {
-			return mailbox_list_index_set_corrupted(ctx->index,
-				"Desync: uid_validity changed");
-		}
-	}
-
-	if (hdr->uid_validity == 0) {
+	mail_hdr = mail_index_get_header(ctx->mail_view);
+	uid_validity = mail_hdr->uid_validity;
+
+	if (uid_validity != 0 || mail_hdr->next_uid != 1) {
+		if (uid_validity != ctx->hdr.uid_validity) {
+			i_warning("%s: Desync: uid_validity changed %u -> %u",
+				  ctx->index->mail_index->filepath,
+				  uid_validity, ctx->hdr.uid_validity);
+			uid_validity = 0;
+			mail_index_reset(ctx->trans);
+		}
+	}
+
+	if (uid_validity != ctx->hdr.uid_validity ) {
 		mail_index_update_header(ctx->trans,
 			offsetof(struct mail_index_header, uid_validity),
 			&ctx->hdr.uid_validity, sizeof(ctx->hdr.uid_validity),
diff -r c5919ea0cb33 -r 461496644c67 src/lib-index/mailbox-list-index.c
--- a/src/lib-index/mailbox-list-index.c	Wed Jul 18 08:18:56 2007 +0300
+++ b/src/lib-index/mailbox-list-index.c	Wed Jul 18 08:20:43 2007 +0300
@@ -601,15 +601,15 @@ int mailbox_list_index_view_init(struct 
 				 struct mailbox_list_index_view **view_r)
 {
 	struct mailbox_list_index_view *view;
-	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) {
+	const struct mail_index_header *mail_hdr;
+
+	mail_hdr = mail_view != NULL ? mail_index_get_header(mail_view) : NULL;
+	if (mail_hdr != NULL && index->hdr != NULL &&
+	    mail_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);
+			mail_hdr->uid_validity);
 		return -1;
 	}
 
diff -r c5919ea0cb33 -r 461496644c67 src/lib-storage/list/index-mailbox-list.c
--- a/src/lib-storage/list/index-mailbox-list.c	Wed Jul 18 08:18:56 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list.c	Wed Jul 18 08:20:43 2007 +0300
@@ -64,6 +64,11 @@ index_mailbox_list_is_synced(struct inde
 	struct stat st;
 	const char *path = ctx->ctx.list->set.root_dir;
 
+	if (ctx->view == NULL) {
+		/* uid_validity changed */
+		return 0;
+	}
+
 	/* FIXME: single sync_stamp works only with maildir++ */
 	if (stat(path, &st) < 0) {
 		mailbox_list_set_critical(ctx->ctx.list,
@@ -212,7 +217,7 @@ index_mailbox_list_iter_init_try(struct 
 	ctx->mail_view = mail_index_view_open(ilist->mail_index);
 	if (mailbox_list_index_view_init(ilist->list_index,
 					 ctx->mail_view, &ctx->view) < 0)
-		return FALSE;
+		ctx->view = NULL;
 
 	/* FIXME: we could just do multiple lookups for different patterns */
 	prefix = NULL;
@@ -233,7 +238,8 @@ index_mailbox_list_iter_init_try(struct 
 
 		/* updated, we'll have to reopen views */
 		mail_index_view_close(&ctx->mail_view);
-		mailbox_list_index_view_deinit(&ctx->view);
+		if (ctx->view != NULL)
+			mailbox_list_index_view_deinit(&ctx->view);
 
 		ctx->mail_view = mail_index_view_open(ilist->mail_index);
 		if (mailbox_list_index_view_init(ilist->list_index,


More information about the dovecot-cvs mailing list