changeset 5399:9be95726e29f HEAD

When adding new keywords, update the index file atomically so the keywords won't break if we crash in the middle of the header update.
author Timo Sirainen <tss@iki.fi>
date Sat, 24 Mar 2007 23:32:06 +0200
parents 730156248978
children 37e87dbdcae6
files src/lib-index/mail-index-sync-keywords.c
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync-keywords.c	Sat Mar 24 23:20:06 2007 +0200
+++ b/src/lib-index/mail-index-sync-keywords.c	Sat Mar 24 23:32:06 2007 +0200
@@ -120,6 +120,15 @@
 	unsigned int keywords_count;
 	int ret;
 
+	if (!map->write_to_disk) {
+		/* if we crash in the middle of writing the header, the
+		   keywords are more or less corrupted. avoid that by
+		   making sure the header is updated atomically. */
+		map = mail_index_map_clone(map, map->hdr.record_size);
+		mail_index_sync_replace_map(ctx, map);
+	}
+	i_assert(MAIL_INDEX_MAP_IS_IN_MEMORY(map));
+
 	ext_id = mail_index_map_lookup_ext(map, "keywords");
 	if (ext_id != (uint32_t)-1) {
 		/* update existing header */