# HG changeset patch # User Timo Sirainen # Date 1174771926 -7200 # Node ID 9be95726e29fd5fe76816aa7c828b14d26d1e352 # Parent 730156248978223ac6e34659ecb37f79a2cb9a16 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. diff -r 730156248978 -r 9be95726e29f src/lib-index/mail-index-sync-keywords.c --- 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 */