[dovecot-cvs] dovecot/src/lib-index mail-index-sync-keywords.c, 1.13, 1.14

tss at dovecot.org tss at dovecot.org
Sat Mar 24 23:32:12 EET 2007


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

Modified Files:
	mail-index-sync-keywords.c 
Log Message:
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.



Index: mail-index-sync-keywords.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-sync-keywords.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mail-index-sync-keywords.c	22 Jan 2007 11:54:58 -0000	1.13
+++ mail-index-sync-keywords.c	24 Mar 2007 21:32:06 -0000	1.14
@@ -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 */



More information about the dovecot-cvs mailing list