[dovecot-cvs] dovecot/src/lib-index mail-index-sync-update.c, 1.101, 1.102

cras at dovecot.org cras at dovecot.org
Sun Jul 23 20:32:45 EEST 2006


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

Modified Files:
	mail-index-sync-update.c 
Log Message:
If header counters got broken when updating internal views, say it clearly
in error messages instead of saying they're broken in the files themselves.



Index: mail-index-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-update.c,v
retrieving revision 1.101
retrieving revision 1.102
diff -u -d -r1.101 -r1.102
--- mail-index-sync-update.c	11 Jul 2006 16:02:42 -0000	1.101
+++ mail-index-sync-update.c	23 Jul 2006 17:32:43 -0000	1.102
@@ -43,57 +43,77 @@
 	i_assert(view->hdr.messages_count == map->hdr.messages_count);
 }
 
-static void
-mail_index_header_update_counts(struct mail_index *index,
-				struct mail_index_header *hdr,
-				uint8_t old_flags, uint8_t new_flags)
+static int
+mail_index_header_update_counts(struct mail_index_header *hdr,
+				uint8_t old_flags, uint8_t new_flags,
+				const char **error_r)
 {
 	if (((old_flags ^ new_flags) & MAIL_RECENT) != 0) {
 		/* different recent-flag */
-		if ((old_flags & MAIL_RECENT) == 0)
+		if ((old_flags & MAIL_RECENT) == 0) {
 			hdr->recent_messages_count++;
-		else if (hdr->recent_messages_count == 0 ||
-			 hdr->recent_messages_count > hdr->messages_count) {
-                        hdr->flags |= MAIL_INDEX_HDR_FLAG_FSCK;
-			mail_index_set_error(index,
-				"Recent counter wrong in index file %s",
-				index->filepath);
-		} else if (--hdr->recent_messages_count == 0)
-			hdr->first_recent_uid_lowwater = hdr->next_uid;
+			if (hdr->recent_messages_count > hdr->messages_count) {
+				*error_r = "Recent counter wrong";
+				return -1;
+			}
+		} else {
+			if (hdr->recent_messages_count == 0 ||
+			    hdr->recent_messages_count > hdr->messages_count) {
+				*error_r = "Recent counter wrong";
+				return -1;
+			}
+
+			if (--hdr->recent_messages_count == 0)
+				hdr->first_recent_uid_lowwater = hdr->next_uid;
+		}
 	}
 
 	if (((old_flags ^ new_flags) & MAIL_SEEN) != 0) {
 		/* different seen-flag */
-		if ((old_flags & MAIL_SEEN) != 0)
+		if ((old_flags & MAIL_SEEN) != 0) {
+			if (hdr->seen_messages_count == 0) {
+				*error_r = "Seen counter wrong";
+				return -1;
+			}
 			hdr->seen_messages_count--;
-		else if (hdr->seen_messages_count >= hdr->messages_count) {
-                        hdr->flags |= MAIL_INDEX_HDR_FLAG_FSCK;
-			mail_index_set_error(index,
-				"Seen counter wrong in index file %s",
-				index->filepath);
-		} else if (++hdr->seen_messages_count == hdr->messages_count)
-			hdr->first_unseen_uid_lowwater = hdr->next_uid;
+		} else {
+			if (hdr->seen_messages_count >= hdr->messages_count) {
+				*error_r = "Seen counter wrong";
+				return -1;
+			}
+
+			if (++hdr->seen_messages_count == hdr->messages_count)
+				hdr->first_unseen_uid_lowwater = hdr->next_uid;
+		}
 	}
 
 	if (((old_flags ^ new_flags) & MAIL_DELETED) != 0) {
 		/* different deleted-flag */
-		if ((old_flags & MAIL_DELETED) == 0)
+		if ((old_flags & MAIL_DELETED) == 0) {
 			hdr->deleted_messages_count++;
-		else if (hdr->deleted_messages_count == 0 ||
-			 hdr->deleted_messages_count > hdr->messages_count) {
-                        hdr->flags |= MAIL_INDEX_HDR_FLAG_FSCK;
-			mail_index_set_error(index,
-				"Deleted counter wrong in index file %s",
-				index->filepath);
-		} else if (--hdr->deleted_messages_count == 0)
-			hdr->first_deleted_uid_lowwater = hdr->next_uid;
+			if (hdr->deleted_messages_count > hdr->messages_count) {
+				*error_r = "Deleted counter wrong";
+				return -1;
+			}
+		} else {
+			if (hdr->deleted_messages_count == 0 ||
+			    hdr->deleted_messages_count > hdr->messages_count) {
+				*error_r = "Deleted counter wrong";
+				return -1;
+			}
+
+			if (--hdr->deleted_messages_count == 0)
+				hdr->first_deleted_uid_lowwater = hdr->next_uid;
+		}
 	}
+	return 0;
 }
 
 void mail_index_view_recalc_counters(struct mail_index_view *view)
 {
 	struct mail_index_map *map = view->map;
 	const struct mail_index_record *rec;
+	const char *error;
 	unsigned int i;
 
 	map->hdr.recent_messages_count = 0;
@@ -102,8 +122,9 @@
 
 	for (i = 0; i < view->hdr.messages_count; i++) {
 		rec = MAIL_INDEX_MAP_IDX(map, i);
-		mail_index_header_update_counts(view->index, &map->hdr,
-						0, rec->flags);
+		if (mail_index_header_update_counts(&map->hdr, 0, rec->flags,
+						    &error) < 0)
+			i_panic("mail_index_view_recalc_counters(): %s", error);
 	}
 
 	view->hdr.recent_messages_count = map->hdr.recent_messages_count;
@@ -134,6 +155,7 @@
 	struct mail_index_view *view = ctx->view;
 	struct mail_index_map *map = view->map;
 	struct mail_index_record *rec;
+	const char *error;
 	uint32_t count, seq, seq1, seq2;
         const struct mail_index_expunge_handler *expunge_handlers, *eh;
 	unsigned int i, expunge_handlers_count;
@@ -185,8 +207,12 @@
 	else {
 		for (seq = seq1; seq <= seq2; seq++) {
 			rec = MAIL_INDEX_MAP_IDX(map, seq-1);
-			mail_index_header_update_counts(view->index, &map->hdr,
-							rec->flags, 0);
+			if (mail_index_header_update_counts(&map->hdr,
+							    rec->flags, 0,
+							    &error) < 0) {
+				mail_index_sync_set_corrupted(ctx, "%s", error);
+				return -1;
+			}
 		}
 	}
 
@@ -234,6 +260,7 @@
 {
 	struct mail_index_view *view = ctx->view;
 	struct mail_index_map *map = view->map;
+	const char *error;
 	void *dest;
 
 	if (rec->uid < map->hdr.next_uid) {
@@ -269,8 +296,11 @@
 		map->hdr.flags |= MAIL_INDEX_HDR_FLAG_HAVE_DIRTY;
 
 	if (!view->broken_counters) {
-		mail_index_header_update_counts(view->index, &map->hdr,
-						0, rec->flags);
+		if (mail_index_header_update_counts(&map->hdr, 0, rec->flags,
+						    &error) < 0) {
+			mail_index_sync_set_corrupted(ctx, "%s", error);
+			return -1;
+		}
 		mail_index_header_update_lowwaters(&map->hdr, rec);
 	}
 	return 1;
@@ -282,6 +312,7 @@
 	struct mail_index_view *view = ctx->view;
 	struct mail_index_header *hdr;
 	struct mail_index_record *rec;
+	const char *error;
 	uint8_t flag_mask, old_flags;
 	uint32_t idx, seq1, seq2;
 
@@ -325,8 +356,12 @@
 			old_flags = rec->flags;
 			rec->flags = (rec->flags & flag_mask) | u->add_flags;
 
-			mail_index_header_update_counts(view->index, hdr,
-							old_flags, rec->flags);
+			if (mail_index_header_update_counts(hdr, old_flags,
+							    rec->flags,
+							    &error) < 0) {
+				mail_index_sync_set_corrupted(ctx, "%s", error);
+				return -1;
+			}
 			mail_index_header_update_lowwaters(hdr, rec);
 		}
 	}



More information about the dovecot-cvs mailing list