changeset 2922:fadf33c24902 HEAD

With mmap_disabled=no the index header wasn't always updated causing various problems.
author Timo Sirainen <tss@iki.fi>
date Tue, 30 Nov 2004 10:59:26 +0200
parents a5eda271256f
children 52000679a7aa
files src/lib-index/mail-index.c
diffstat 1 files changed, 16 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Mon Nov 29 20:01:26 2004 +0200
+++ b/src/lib-index/mail-index.c	Tue Nov 30 10:59:26 2004 +0200
@@ -371,6 +371,19 @@
 	mail_index_unmap(index, map);
 }
 
+static void mail_index_map_copy_hdr(struct mail_index_map *map,
+				    const struct mail_index_header *hdr)
+{
+	if (hdr->base_header_size < sizeof(map->hdr)) {
+		/* header smaller than ours, make a copy so our newer headers
+		   won't have garbage in them */
+		memset(&map->hdr, 0, sizeof(map->hdr));
+		memcpy(&map->hdr, hdr, hdr->base_header_size);
+	} else {
+		map->hdr = *hdr;
+	}
+}
+
 static int mail_index_mmap(struct mail_index *index, struct mail_index_map *map)
 {
 	const struct mail_index_header *hdr;
@@ -421,14 +434,7 @@
 		return 0;
 	}
 
-	if (hdr->base_header_size < sizeof(map->hdr)) {
-		/* header smaller than ours, make a copy so our newer headers
-		   won't have garbage in them */
-		memset(&map->hdr, 0, sizeof(map->hdr));
-		memcpy(&map->hdr, hdr, hdr->base_header_size);
-	} else {
-		map->hdr = *hdr;
-	}
+	mail_index_map_copy_hdr(map, hdr);
 
 	map->hdr_base = map->mmap_base;
 	map->records = PTR_OFFSET(map->mmap_base, map->hdr.header_size);
@@ -531,12 +537,7 @@
 	map->records = data;
 	map->records_count = hdr.messages_count;
 
-	if (hdr.base_header_size >= sizeof(map->hdr))
-		map->hdr = hdr;
-	else {
-		memset(&map->hdr, 0, sizeof(map->hdr));
-		memcpy(&map->hdr, &hdr, hdr.base_header_size);
-	}
+	mail_index_map_copy_hdr(map, &hdr);
 	map->hdr_base = map->hdr_copy_buf->data;
 
 	index->sync_log_file_seq = hdr.log_file_seq;
@@ -698,6 +699,7 @@
 	used_size = hdr->header_size + hdr->messages_count * hdr->record_size;
 	if (map->mmap_size >= used_size && map->hdr_base == hdr) {
 		map->records_count = hdr->messages_count;
+		mail_index_map_copy_hdr(map, hdr);
 		return 1;
 	}
 	return 0;