changeset 2586:6bff38d73dd3 HEAD

Before adding new fields to cache file, make sure they weren't already added by re-reading the header after file is locked.
author Timo Sirainen <tss@iki.fi>
date Sat, 11 Sep 2004 12:59:03 +0300
parents bd0ffdd2afde
children 7ba2e2d89536
files src/lib-index/mail-cache-transaction.c
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-transaction.c	Fri Sep 10 15:31:28 2004 +0300
+++ b/src/lib-index/mail-cache-transaction.c	Sat Sep 11 12:59:03 2004 +0300
@@ -511,8 +511,8 @@
 	mail_cache_transaction_free(ctx);
 }
 
-static int
-mail_cache_header_write_fields(struct mail_cache_transaction_ctx *ctx)
+static int mail_cache_header_add_field(struct mail_cache_transaction_ctx *ctx,
+				       unsigned int field)
 {
 	struct mail_cache *cache = ctx->cache;
 	buffer_t *buffer;
@@ -524,6 +524,18 @@
 	if (mail_cache_lock(cache) <= 0)
 		return -1;
 
+	/* re-read header to make sure we don't lose any fields. */
+	if (mail_cache_header_fields_read(cache) < 0) {
+		mail_cache_unlock(cache);
+		return -1;
+	}
+
+	if (ctx->cache->field_file_map[field] != (uint32_t)-1) {
+		/* it was already added */
+		mail_cache_unlock(cache);
+		return 0;
+	}
+
 	t_push();
 	buffer = buffer_create_dynamic(pool_datastack_create(),
 				       256, (size_t)-1);
@@ -578,7 +590,7 @@
 	file_field = ctx->cache->field_file_map[field];
 	if (file_field == (uint32_t)-1) {
 		/* we'll have to add this field to headers */
-		if (mail_cache_header_write_fields(ctx) < 0)
+		if (mail_cache_header_add_field(ctx, field) < 0)
 			return;
 
 		file_field = ctx->cache->field_file_map[field];