changeset 5946:19bc2a4b3669 HEAD

Added mail_index_ext_set_reset_id().
author Timo Sirainen <tss@iki.fi>
date Thu, 12 Jul 2007 02:32:44 +0300
parents ab487f1de905
children 7ebe0593f488
files src/lib-index/mail-index-transaction-private.h src/lib-index/mail-index-transaction.c src/lib-index/mail-index.h src/lib-index/mail-transaction-log-append.c
diffstat 4 files changed, 34 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-transaction-private.h	Thu Jul 12 02:23:59 2007 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Thu Jul 12 02:32:44 2007 +0300
@@ -51,6 +51,7 @@
 	ARRAY_DEFINE(ext_rec_updates, ARRAY_TYPE(seq_array));
 	ARRAY_DEFINE(ext_resizes, struct mail_transaction_ext_intro);
 	ARRAY_DEFINE(ext_resets, uint32_t);
+	ARRAY_DEFINE(ext_reset_ids, uint32_t);
 
 	ARRAY_DEFINE(keyword_updates,
 		     struct mail_index_transaction_keyword_update);
--- a/src/lib-index/mail-index-transaction.c	Thu Jul 12 02:23:59 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c	Thu Jul 12 02:32:44 2007 +0300
@@ -849,6 +849,16 @@
 
 	t->log_updates = TRUE;
 
+	mail_index_ext_set_reset_id(t, ext_id, reset_id);
+
+	if (!array_is_created(&t->ext_resets))
+		i_array_init(&t->ext_resets, ext_id + 2);
+	array_idx_set(&t->ext_resets, ext_id, &reset_id);
+}
+
+void mail_index_ext_set_reset_id(struct mail_index_transaction *t,
+				 uint32_t ext_id, uint32_t reset_id)
+{
 	if (array_is_created(&t->ext_rec_updates) &&
 	    ext_id < array_count(&t->ext_rec_updates)) {
 		/* if extension records have been updated, clear them */
@@ -859,9 +869,9 @@
 			array_clear(array);
 	}
 
-	if (!array_is_created(&t->ext_resets))
-		i_array_init(&t->ext_resets, ext_id + 2);
-	array_idx_set(&t->ext_resets, ext_id, &reset_id);
+	if (!array_is_created(&t->ext_reset_ids))
+		i_array_init(&t->ext_reset_ids, ext_id + 2);
+	array_idx_set(&t->ext_reset_ids, ext_id, &reset_id);
 }
 
 void mail_index_update_header_ext(struct mail_index_transaction *t,
--- a/src/lib-index/mail-index.h	Thu Jul 12 02:23:59 2007 +0300
+++ b/src/lib-index/mail-index.h	Thu Jul 12 02:32:44 2007 +0300
@@ -391,6 +391,11 @@
    used to figure this out, so it must be different every time. */
 void mail_index_ext_reset(struct mail_index_transaction *t, uint32_t ext_id,
 			  uint32_t reset_id);
+/* Discard existing extension updates and write new updates using the given
+   reset_id. The difference to mail_index_ext_reset() is that this doesn't
+   clear any existing record or header data. */
+void mail_index_ext_set_reset_id(struct mail_index_transaction *t,
+				 uint32_t ext_id, uint32_t reset_id);
 
 /* Returns extension header. */
 int mail_index_get_header_ext(struct mail_index_view *view, uint32_t ext_id,
--- a/src/lib-index/mail-transaction-log-append.c	Thu Jul 12 02:23:59 2007 +0300
+++ b/src/lib-index/mail-transaction-log-append.c	Thu Jul 12 02:32:44 2007 +0300
@@ -251,10 +251,10 @@
         const struct mail_transaction_ext_intro *resize;
 	struct mail_index_transaction_ext_hdr_update *const *hdrs;
 	struct mail_transaction_ext_reset ext_reset;
-	unsigned int update_count, resize_count, reset_count, ext_count = 0;
-	unsigned int hdrs_count;
+	unsigned int update_count, resize_count, ext_count = 0;
+	unsigned int hdrs_count, reset_id_count, reset_count;
 	uint32_t ext_id;
-	const uint32_t *reset;
+	const uint32_t *reset_ids, *reset;
 	const ARRAY_TYPE(seq_array) *update;
 	buffer_t *buf;
 
@@ -275,6 +275,13 @@
 			ext_count = resize_count;
 	}
 
+	if (!array_is_created(&t->ext_reset_ids)) {
+		reset_ids = NULL;
+		reset_id_count = 0;
+	} else {
+		reset_ids = array_get(&t->ext_reset_ids, &reset_count);
+	}
+
 	if (!array_is_created(&t->ext_resets)) {
 		reset = NULL;
 		reset_count = 0;
@@ -301,15 +308,15 @@
 
 	for (ext_id = 0; ext_id < ext_count; ext_id++) {
 		ext_reset.new_reset_id =
-			ext_id < reset_count && reset[ext_id] != 0 ?
-			reset[ext_id] : 0;
+			ext_id < reset_id_count && reset_ids[ext_id] != 0 ?
+			reset_ids[ext_id] : 0;
 		if ((ext_id < resize_count && resize[ext_id].name_size) ||
 		    (ext_id < update_count &&
 		     array_is_created(&update[ext_id])) ||
 		    ext_reset.new_reset_id != 0 ||
 		    (ext_id < hdrs_count && hdrs[ext_id] != NULL))
 			log_append_ext_intro(ctx, ext_id, 0);
-		if (ext_reset.new_reset_id != 0) {
+		if (ext_id < reset_count && reset[ext_id] != 0) {
 			log_append_buffer(ctx, buf, NULL,
 					  MAIL_TRANSACTION_EXT_RESET);
 		}
@@ -333,11 +340,11 @@
 		updates = array_get_modifiable(&t->ext_rec_updates, &count);
 	}
 
-	if (!array_is_created(&t->ext_resets)) {
+	if (!array_is_created(&t->ext_reset_ids)) {
 		reset = NULL;
 		reset_count = 0;
 	} else {
-		reset = array_get_modifiable(&t->ext_resets, &reset_count);
+		reset = array_get_modifiable(&t->ext_reset_ids, &reset_count);
 	}
 
 	for (ext_id = 0; ext_id < count; ext_id++) {