changeset 6342:702f13f44c5e HEAD

Check that header is still valid after syncing. If not, fsck.
author Timo Sirainen <tss@iki.fi>
date Sun, 02 Sep 2007 03:04:47 +0300
parents adffeec04dcc
children c76101b824ec
files src/lib-index/mail-index-map.c src/lib-index/mail-index-private.h src/lib-index/mail-index-sync-update.c
diffstat 3 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-map.c	Sat Sep 01 03:14:11 2007 +0300
+++ b/src/lib-index/mail-index-map.c	Sun Sep 02 03:04:47 2007 +0300
@@ -263,7 +263,7 @@
 	return TRUE;
 }
 
-static int mail_index_check_header(struct mail_index_map *map)
+int mail_index_map_check_header(struct mail_index_map *map)
 {
 	struct mail_index *index = map->index;
 	const struct mail_index_header *hdr = &map->hdr;
@@ -684,7 +684,7 @@
 	}
 	if (ret > 0) {
 		/* make sure the header is ok before using this mapping */
-		ret = mail_index_check_header(new_map);
+		ret = mail_index_map_check_header(new_map);
 		if (ret >= 0) {
 			ret = mail_index_parse_extensions(new_map);
 			if (ret > 0) {
--- a/src/lib-index/mail-index-private.h	Sat Sep 01 03:14:11 2007 +0300
+++ b/src/lib-index/mail-index-private.h	Sun Sep 02 03:04:47 2007 +0300
@@ -289,6 +289,7 @@
 const struct mail_index_ext *
 mail_index_view_get_ext(struct mail_index_view *view, uint32_t ext_id);
 
+int mail_index_map_check_header(struct mail_index_map *map);
 int mail_index_map_parse_keywords(struct mail_index_map *map);
 
 void mail_index_view_transaction_ref(struct mail_index_view *view);
--- a/src/lib-index/mail-index-sync-update.c	Sat Sep 01 03:14:11 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Sun Sep 02 03:04:47 2007 +0300
@@ -821,6 +821,14 @@
 
 	i_assert(index->map == map || type == MAIL_INDEX_SYNC_HANDLER_VIEW);
 
+	if (mail_index_map_check_header(map) <= 0) {
+		mail_index_set_error(index,
+			"Synchronization corrupted index header: %s",
+			index->filepath);
+		(void)mail_index_fsck(index);
+		map = index->map;
+	}
+
 	*_map = map;
 	return ret < 0 ? -1 : 1;
 }