changeset 7220:21d1d0ced13e HEAD

Expunge fixes
author Timo Sirainen <tss@iki.fi>
date Sat, 09 Feb 2008 15:11:24 +0200
parents 6c48b72c5096
children e042b6385c7b
files src/plugins/fts-squat/squat-trie.c src/plugins/fts-squat/squat-uidlist.c
diffstat 2 files changed, 15 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/fts-squat/squat-trie.c	Sat Feb 09 14:34:30 2008 +0200
+++ b/src/plugins/fts-squat/squat-trie.c	Sat Feb 09 15:11:24 2008 +0200
@@ -1065,10 +1065,8 @@
 	}
 
 	*shifts_r = ctx->cur.shifts;
-	if (array_is_created(&ctx->cur.shifts)) {
+	if (array_is_created(&ctx->cur.shifts))
 		shift_count = array_count(&ctx->cur.shifts);
-		i_assert(shift_count > 0);
-	}
 
 	children = NODE_CHILDREN_NODES(ctx->cur.node);
 	while (children[ctx->cur.idx++].uid_list_idx == 0) {
@@ -1082,6 +1080,8 @@
 	ctx->cur.idx = 0;
 	if (shift_count != 0)
 		i_array_init(&ctx->cur.shifts, shift_count);
+	else
+		memset(&ctx->cur.shifts, 0, sizeof(ctx->cur.shifts));
 	return squat_trie_iterate_first(ctx);
 }
 
@@ -1097,6 +1097,9 @@
 	uint32_t child_shift_seq1, child_shift_count, seq_high;
 	unsigned int shift_sum = 0, child_sum = 0;
 
+	if (!array_is_created(shifts_arr))
+		return;
+
 	uids = array_get_modifiable(uids_arr, &uid_count);
 	shifts = array_get(shifts_arr, &shift_count);
 	for (i = 0, uid_idx = 0, seq_high = 0;; ) {
@@ -1122,11 +1125,9 @@
 				uid_idx++;
 			}
 		}
-		if (uid_idx == uid_count) {
-			i_assert(array_count(child_shifts) > 0 ||
-				 array_count(uids_arr) == 0);
+		if (uid_idx == uid_count)
 			break;
-		}
+
 		shift.seq1 = I_MAX(shifts[i].seq1, seq_high);
 		shift.seq2 = shifts[i].seq2;
 		if (shift.seq2 < uids[uid_idx].seq1) {
@@ -1206,7 +1207,7 @@
 	i_array_init(&shifts, array_count(expunged_uids));
 	array_append_array(&shifts, expunged_uids);
 
-	while (node != NULL) {
+	do {
 		i_assert(node->uid_list_idx != 0);
 		array_clear(&uid_range);
 		if (squat_uidlist_get_seqrange(ctx->trie->uidlist,
@@ -1224,9 +1225,8 @@
 			node->next_uid = 0;
 		}
 		node = squat_trie_iterate_next(iter, &shifts);
-		i_assert(array_count(&shifts) > 0);
 		shift = TRUE;
-	}
+	} while (node != NULL);
 	array_free(&uid_range);
 	return ret;
 }
--- a/src/plugins/fts-squat/squat-uidlist.c	Sat Feb 09 14:34:30 2008 +0200
+++ b/src/plugins/fts-squat/squat-uidlist.c	Sat Feb 09 15:11:24 2008 +0200
@@ -693,6 +693,7 @@
 
 	if (array_count(block_end_indexes) == 0) {
 		ctx->build_hdr.used_file_size = output->offset;
+		ctx->build_hdr.block_list_offset = 0;
 		uidlist->hdr = ctx->build_hdr;
 		return;
 	}
@@ -940,10 +941,6 @@
 	if (count == 0)
 		return 0;
 
-	if (count == 1 && range[0].seq1 == range[0].seq2) {
-		/* single UID */
-		return (range[0].seq1 << 1) | 1;
-	}
 	if (range[count-1].seq2 < 8) {
 		/* we can use a singleton bitmask */
 		ret = 0;
@@ -953,6 +950,10 @@
 		}
 		return ret;
 	}
+	if (count == 1 && range[0].seq1 == range[0].seq2) {
+		/* single UID */
+		return (range[0].seq1 << 1) | 1;
+	}
 
 	/* convert seq range to our internal representation and use the
 	   normal _rebuild_next() to write it */