dovecot-1.1: sort: Don't assert-crash if sort indexes are broken.

dovecot at dovecot.org dovecot at dovecot.org
Fri Aug 7 23:47:10 EEST 2009


details:   http://hg.dovecot.org/dovecot-1.1/rev/fd48a9c61b6c
changeset: 8340:fd48a9c61b6c
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Aug 07 16:47:02 2009 -0400
description:
sort: Don't assert-crash if sort indexes are broken.

diffstat:

1 file changed, 13 insertions(+), 6 deletions(-)
src/lib-storage/index/index-sort-string.c |   19 +++++++++++++------

diffs (66 lines):

diff -r 876393c6d1ea -r fd48a9c61b6c src/lib-storage/index/index-sort-string.c
--- a/src/lib-storage/index/index-sort-string.c	Tue Aug 04 14:54:36 2009 -0400
+++ b/src/lib-storage/index/index-sort-string.c	Fri Aug 07 16:47:02 2009 -0400
@@ -27,6 +27,7 @@ ARRAY_DEFINE_TYPE(mail_sort_node, struct
 
 struct sort_string_context {
 	struct mail_search_sort_program *program;
+	const char *primary_sort_name;
 
 	ARRAY_TYPE(mail_sort_node) zero_nodes, nonzero_nodes, sorted_nodes;
 	const char **sort_strings;
@@ -40,11 +41,13 @@ struct sort_string_context {
 	unsigned int have_all_wanted:1;
 	unsigned int no_writing:1;
 	unsigned int reverse:1;
+	unsigned int broken:1;
 };
 
 static char expunged_msg;
 static struct sort_string_context *static_zero_cmp_context;
 
+static void index_sort_list_reset_broken(struct sort_string_context *ctx);
 static void index_sort_node_add(struct sort_string_context *ctx,
 				struct mail_sort_node *node);
 
@@ -74,6 +77,7 @@ void index_sort_list_init_string(struct 
 	program->context = ctx = i_new(struct sort_string_context, 1);
 	ctx->reverse = (program->sort_program[0] & MAIL_SORT_FLAG_REVERSE) != 0;
 	ctx->program = program;
+	ctx->primary_sort_name = name;
 	ctx->ext_id = mail_index_ext_register(ibox->index, name, 0,
 					      sizeof(uint32_t),
 					      sizeof(uint32_t));
@@ -158,14 +162,17 @@ static void index_sort_node_add(struct s
 		   highest_reset_id, but this isn't currently possible. */
 		node->sort_id = 0;
 	} else {
-		node->sort_id = data == NULL ? 0 : *(const uint32_t *)data;
+		node->sort_id = ctx->broken || data == NULL ? 0 :
+			*(const uint32_t *)data;
 		if (node->sort_id == 0) {
 			if (ctx->lowest_nonexpunged_zero > node->seq ||
 			    ctx->lowest_nonexpunged_zero == 0)
 				ctx->lowest_nonexpunged_zero = node->seq;
-		} else {
-			i_assert(ctx->lowest_nonexpunged_zero == 0 ||
-				 ctx->lowest_nonexpunged_zero > node->seq);
+		} else if (ctx->lowest_nonexpunged_zero != 0 &&
+			   ctx->lowest_nonexpunged_zero <= node->seq) {
+			index_sort_list_reset_broken(ctx);
+			ctx->broken = TRUE;
+			node->sort_id = 0;
 		}
 	}
 
@@ -732,8 +739,8 @@ static void index_sort_list_reset_broken
 	unsigned int i, count;
 
 	mail_storage_set_critical(box->storage,
-				  "Sort IDs %u broken in mailbox %s, resetting",
-				  ctx->ext_id, box->name);
+				  "%s: Broken %s indexes, resetting",
+				  box->name, ctx->primary_sort_name);
 
 	array_clear(&ctx->zero_nodes);
 	array_append_array(&ctx->zero_nodes,


More information about the dovecot-cvs mailing list