[dovecot-cvs] dovecot/src/lib-index mail-index.c, 1.230.2.1, 1.230.2.2

cras at dovecot.org cras at dovecot.org
Thu May 18 12:57:20 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv3098

Modified Files:
      Tag: branch_1_0
	mail-index.c 
Log Message:
If syncing from transaction log fails, fallback to re-reading the index
file (and more importantly, try to avoid crashing in assert..)



Index: mail-index.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.230.2.1
retrieving revision 1.230.2.2
diff -u -d -r1.230.2.1 -r1.230.2.2
--- mail-index.c	10 May 2006 15:11:37 -0000	1.230.2.1
+++ mail-index.c	18 May 2006 09:57:18 -0000	1.230.2.2
@@ -809,7 +809,7 @@
 	uoff_t prev_offset, max_offset;
 	size_t pos;
 	int ret;
-	bool skipped, check_ext_offsets;
+	bool skipped, check_ext_offsets, broken;
 
 	if (sync_to_index) {
 		/* read the real log position where we are supposed to be
@@ -865,7 +865,7 @@
 	mail_index_sync_map_init(&sync_map_ctx, view,
 				 MAIL_INDEX_SYNC_HANDLER_VIEW);
 
-	check_ext_offsets = TRUE;
+	check_ext_offsets = TRUE; broken = FALSE;
 	while ((ret = mail_transaction_log_view_next(log_view, &thdr, &tdata,
 						     &skipped)) > 0) {
 		if ((thdr->type & MAIL_TRANSACTION_EXTERNAL) != 0 &&
@@ -876,10 +876,13 @@
 		}
 
 		if (mail_index_sync_record(&sync_map_ctx, thdr, tdata) < 0) {
-			ret = -1;
+			ret = 0;
+			broken = TRUE;
 			break;
 		}
 	}
+	if (ret == 0 && !broken)
+		ret = 1;
 
 	mail_transaction_log_view_get_prev_pos(log_view, &prev_seq,
 					       &prev_offset);
@@ -897,7 +900,7 @@
 	*map = index->map;
 	index->map = NULL;
 
-	if (sync_to_index) {
+	if (sync_to_index && ret > 0) {
 		/* make sure we did everything right. note that although the
 		   message counts should be equal, the flag counters may not */
 		i_assert(hdr.messages_count == (*map)->hdr.messages_count);
@@ -906,7 +909,7 @@
 		i_assert(hdr.log_file_ext_offset == (*map)->hdr.log_file_ext_offset);
 	}
 
-	return ret < 0 ? -1 : 1;
+	return ret;
 }
 
 static int mail_index_read_map_with_retry(struct mail_index *index,



More information about the dovecot-cvs mailing list