changeset 51:b4adc3429867 HEAD

Some cleanups, assertion fixes.
author Timo Sirainen <tss@iki.fi>
date Wed, 28 Aug 2002 00:04:08 +0300
parents d493b9cc265e
children d5f0f634b86e
files src/lib-storage/index/index-search.c
diffstat 1 files changed, 17 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-search.c	Tue Aug 27 22:16:54 2002 +0300
+++ b/src/lib-storage/index/index-search.c	Wed Aug 28 00:04:08 2002 +0300
@@ -585,6 +585,10 @@
 	search_get_sequid(ibox, args, first_seq, last_seq,
 			  &first_uid, &last_uid);
 
+	/* seq_update() should make sure that these can't happen */
+	i_assert(*first_seq >= *last_seq);
+	i_assert(first_uid >= last_uid);
+
 	if (first_uid != 0 && (*first_seq != 1 ||
 			       *last_seq != ibox->synced_messages_count)) {
 		/* UIDs were used - see if they affect the sequences */
@@ -613,6 +617,8 @@
 		*first_seq = 1;
 	if (*last_seq == 0)
 		*last_seq = ibox->synced_messages_count;
+
+	i_assert(*first_seq >= *last_seq);
 }
 
 static void search_messages(IndexMailbox *ibox, MailSearchArg *args,
@@ -623,16 +629,13 @@
 	unsigned int first_seq, last_seq, seq;
 	char num[MAX_INT_STRLEN+10];
 
+	if (ibox->synced_messages_count == 0)
+		return;
+
 	/* see if we can limit the records we look at */
 	search_get_sequences(ibox, args, &first_seq, &last_seq);
 
-	if (first_seq > last_seq) {
-		/* not possible */
-		return;
-	}
-
 	ctx.ibox = ibox;
-
 	rec = ibox->index->lookup(ibox->index, first_seq);
 	for (seq = first_seq; rec != NULL && seq <= last_seq; seq++) {
 		ctx.rec = rec;
@@ -657,21 +660,16 @@
 			 IOBuffer *outbuf, int uid_result)
 {
 	IndexMailbox *ibox = (IndexMailbox *) box;
-	int failed;
 
 	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_SHARED))
-		failed = TRUE;
-	else {
-		io_buffer_send(outbuf, "* SEARCH", 8);
+		return mail_storage_set_index_error(ibox);
+
+	io_buffer_send(outbuf, "* SEARCH", 8);
+	search_messages(ibox, args, outbuf, uid_result);
+	io_buffer_send(outbuf, "\r\n", 2);
 
-		search_messages(ibox, args, outbuf, uid_result);
-		failed = !ibox->index->set_lock(ibox->index,
-						MAIL_LOCK_UNLOCK);
-		io_buffer_send(outbuf, "\r\n", 2);
-	}
+	if (!ibox->index->set_lock(ibox->index, MAIL_LOCK_UNLOCK))
+		return mail_storage_set_index_error(ibox);
 
-	if (failed)
-		(void)mail_storage_set_index_error(ibox);
-
-	return !failed;
+	return TRUE;
 }