dovecot: Reverted fix for dropping expunged messages from flag u...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jan 7 07:38:22 EET 2008


details:   http://hg.dovecot.org/dovecot/rev/a1d1f7c9671e
changeset: 7132:a1d1f7c9671e
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jan 07 07:34:08 2008 +0200
description:
Reverted fix for dropping expunged messages from flag updates. It's more
common that the UID range was actually meant to include the expunged
message.

diffstat:

4 files changed, 32 insertions(+), 100 deletions(-)
src/lib-index/mail-index-sync-keywords.c |   41 +++++++++--------
src/lib-index/mail-index-sync-private.h  |   11 ----
src/lib-index/mail-index-sync-update.c   |   70 ++----------------------------
src/lib-index/mail-index-view-sync.c     |   10 +---

diffs (258 lines):

diff -r 0355a4603e80 -r a1d1f7c9671e src/lib-index/mail-index-sync-keywords.c
--- a/src/lib-index/mail-index-sync-keywords.c	Sun Jan 06 16:29:19 2008 +0200
+++ b/src/lib-index/mail-index-sync-keywords.c	Mon Jan 07 07:34:08 2008 +0200
@@ -191,18 +191,22 @@ keywords_header_add(struct mail_index_sy
 	i_assert(*keyword_idx_r / CHAR_BIT < ext->record_size);
 }
 
-static void
+static int
 keywords_update_records(struct mail_index_sync_map_ctx *ctx,
 			const struct mail_index_ext *ext,
 			unsigned int keyword_idx, enum modify_type type,
-			uint32_t seq1, uint32_t seq2)
+			uint32_t uid1, uint32_t uid2)
 {
 	struct mail_index_view *view = ctx->view;
 	struct mail_index_record *rec;
 	unsigned char *data, data_mask;
 	unsigned int data_offset;
+	uint32_t seq1, seq2;
 
 	i_assert(keyword_idx != (unsigned int)-1);
+
+	if (!mail_index_lookup_seq_range(view, uid1, uid2, &seq1, &seq2))
+		return 1;
 
 	mail_index_sync_write_seq_update(ctx, seq1, seq2);
 
@@ -233,6 +237,7 @@ keywords_update_records(struct mail_inde
 	default:
 		i_unreached();
 	}
+	return 1;
 }
 
 int mail_index_sync_keywords(struct mail_index_sync_map_ctx *ctx,
@@ -243,10 +248,9 @@ int mail_index_sync_keywords(struct mail
 	const char *keyword_name;
 	const struct mail_index_ext *ext;
 	const uint32_t *uid, *end;
-	struct sync_uid_range_iter iter;
-	uint32_t seq1, seq2;
 	uint32_t seqset_offset, ext_map_idx;
 	unsigned int keyword_idx;
+	int ret;
 
 	seqset_offset = sizeof(*rec) + rec->name_size;
 	if ((seqset_offset % 4) != 0)
@@ -289,11 +293,12 @@ int mail_index_sync_keywords(struct mail
 	}
 
 	while (uid+2 <= end) {
-		sync_uid_range_iter_init(&iter, ctx, uid[0], uid[1]);
-		while (sync_uid_range_iter_next(&iter, &seq1, &seq2)) {
-			keywords_update_records(ctx, ext, keyword_idx,
-						rec->modify_type, seq1, seq2);
-		}
+		ret = keywords_update_records(ctx, ext, keyword_idx,
+					      rec->modify_type,
+					      uid[0], uid[1]);
+		if (ret <= 0)
+			return ret;
+
 		uid += 2;
 	}
 
@@ -309,7 +314,6 @@ mail_index_sync_keywords_reset(struct ma
 	struct mail_index_record *rec;
 	const struct mail_index_ext *ext;
 	const struct mail_transaction_keyword_reset *end;
-	struct sync_uid_range_iter iter;
 	uint32_t ext_map_idx, seq1, seq2;
 
 	if (!mail_index_map_lookup_ext(map, "keywords", &ext_map_idx)) {
@@ -320,14 +324,15 @@ mail_index_sync_keywords_reset(struct ma
 	ext = array_idx(&map->extensions, ext_map_idx);
 	end = CONST_PTR_OFFSET(r, hdr->size);
 	for (; r != end; r++) {
-		sync_uid_range_iter_init(&iter, ctx, r->uid1, r->uid2);
-		while (sync_uid_range_iter_next(&iter, &seq1, &seq2)) {
-			mail_index_sync_write_seq_update(ctx, seq1, seq2);
-			for (seq1--; seq1 < seq2; seq1++) {
-				rec = MAIL_INDEX_MAP_IDX(map, seq1);
-				memset(PTR_OFFSET(rec, ext->record_offset),
-				       0, ext->record_size);
-			}
+		if (!mail_index_lookup_seq_range(ctx->view, r->uid1, r->uid2,
+						 &seq1, &seq2))
+			continue;
+
+		mail_index_sync_write_seq_update(ctx, seq1, seq2);
+		for (seq1--; seq1 < seq2; seq1++) {
+			rec = MAIL_INDEX_MAP_IDX(map, seq1);
+			memset(PTR_OFFSET(rec, ext->record_offset),
+			       0, ext->record_size);
 		}
 	}
 	return 1;
diff -r 0355a4603e80 -r a1d1f7c9671e src/lib-index/mail-index-sync-private.h
--- a/src/lib-index/mail-index-sync-private.h	Sun Jan 06 16:29:19 2008 +0200
+++ b/src/lib-index/mail-index-sync-private.h	Mon Jan 07 07:34:08 2008 +0200
@@ -7,11 +7,6 @@ struct uid_range {
 	uint32_t uid1, uid2;
 };
 ARRAY_DEFINE_TYPE(uid_range, struct uid_range);
-
-struct sync_uid_range_iter {
-	struct mail_index_sync_map_ctx *ctx;
-	uint32_t seq1, seq2;
-};
 
 struct mail_index_sync_list {
 	const ARRAY_TYPE(uid_range) *array;
@@ -57,12 +52,6 @@ int mail_index_sync_map(struct mail_inde
 int mail_index_sync_map(struct mail_index_map **map,
 			enum mail_index_sync_handler_type type, bool force);
 
-void sync_uid_range_iter_init(struct sync_uid_range_iter *iter,
-			      struct mail_index_sync_map_ctx *ctx,
-			      uint32_t uid1, uint32_t uid2);
-bool sync_uid_range_iter_next(struct sync_uid_range_iter *iter,
-			      uint32_t *seq1_r, uint32_t *seq2_r);
-
 int mail_index_sync_record(struct mail_index_sync_map_ctx *ctx,
 			   const struct mail_transaction_header *hdr,
 			   const void *data);
diff -r 0355a4603e80 -r a1d1f7c9671e src/lib-index/mail-index-sync-update.c
--- a/src/lib-index/mail-index-sync-update.c	Sun Jan 06 16:29:19 2008 +0200
+++ b/src/lib-index/mail-index-sync-update.c	Mon Jan 07 07:34:08 2008 +0200
@@ -86,55 +86,6 @@ mail_index_sync_get_atomic_map(struct ma
 	mail_index_record_map_move_to_private(ctx->view->map);
 	ctx->view->map->write_atomic = TRUE;
 	return ctx->view->map;
-}
-
-void sync_uid_range_iter_init(struct sync_uid_range_iter *iter,
-			      struct mail_index_sync_map_ctx *ctx,
-			      uint32_t uid1, uint32_t uid2)
-{
-	memset(iter, 0, sizeof(*iter));
-	iter->ctx = ctx;
-	if (!mail_index_lookup_seq_range(ctx->view, uid1, uid2,
-					 &iter->seq1, &iter->seq2))
-		iter->seq1 = 1;
-}
-
-bool sync_uid_range_iter_next(struct sync_uid_range_iter *iter,
-			      uint32_t *seq1_r, uint32_t *seq2_r)
-{
-	struct mail_index_view *view;
-	uint32_t seq;
-
-	if (iter->seq1 > iter->seq2)
-		return FALSE;
-
-	if (iter->ctx->type != MAIL_INDEX_SYNC_HANDLER_VIEW) {
-		*seq1_r = iter->seq1;
-		*seq2_r = iter->seq2;
-		iter->seq1 = iter->seq2 + 1;
-		return TRUE;
-	}
-	view = iter->ctx->view;
-
-	/* with views we have to drop expunged messages from the range.
-	   first skip over any expunged messages from the beginning of the
-	   range. */
-	for (seq = iter->seq1; seq <= iter->seq2; seq++) {
-		if (!mail_index_is_expunged(view, seq))
-			break;
-	}
-	if (seq > iter->seq2)
-		return FALSE;
-	*seq1_r = seq;
-
-	/* go forward until we find the first expunged message */
-	for (seq++; seq <= iter->seq2; seq++) {
-		if (mail_index_is_expunged(view, seq))
-			break;
-	}
-	*seq2_r = seq - 1;
-	iter->seq1 = seq;
-	return TRUE;
 }
 
 static int
@@ -387,14 +338,16 @@ static int sync_append(const struct mail
 	return 1;
 }
 
-static void sync_flag_update_range(struct mail_index_sync_map_ctx *ctx,
-				   const struct mail_transaction_flag_update *u,
-				   uint32_t seq1, uint32_t seq2)
+static int sync_flag_update(const struct mail_transaction_flag_update *u,
+			    struct mail_index_sync_map_ctx *ctx)
 {
 	struct mail_index_view *view = ctx->view;
 	struct mail_index_record *rec;
 	uint8_t flag_mask, old_flags;
-	uint32_t idx;
+	uint32_t idx, seq1, seq2;
+
+	if (!mail_index_lookup_seq_range(view, u->uid1, u->uid2, &seq1, &seq2))
+		return 1;
 
 	mail_index_sync_write_seq_update(ctx, seq1, seq2);
 
@@ -424,17 +377,6 @@ static void sync_flag_update_range(struc
 							     rec->flags, TRUE);
 		}
 	}
-}
-
-static int sync_flag_update(const struct mail_transaction_flag_update *u,
-			    struct mail_index_sync_map_ctx *ctx)
-{
-	struct sync_uid_range_iter iter;
-	uint32_t seq1, seq2;
-
-	sync_uid_range_iter_init(&iter, ctx, u->uid1, u->uid2);
-	while (sync_uid_range_iter_next(&iter, &seq1, &seq2))
-		sync_flag_update_range(ctx, u, seq1, seq2);
 	return 1;
 }
 
diff -r 0355a4603e80 -r a1d1f7c9671e src/lib-index/mail-index-view-sync.c
--- a/src/lib-index/mail-index-view-sync.c	Sun Jan 06 16:29:19 2008 +0200
+++ b/src/lib-index/mail-index-view-sync.c	Mon Jan 07 07:34:08 2008 +0200
@@ -309,6 +309,8 @@ int mail_index_view_sync_begin(struct ma
 	ctx->expunges = expunges;
 	ctx->finish_min_msg_count = reset || quick_sync ? 0 :
 		view->map->hdr.messages_count - expunge_count;
+	mail_index_sync_map_init(&ctx->sync_map_ctx, view,
+				 MAIL_INDEX_SYNC_HANDLER_VIEW);
 
 	if (reset && view->map->hdr.messages_count > 0 &&
 	    (flags & MAIL_INDEX_VIEW_SYNC_FLAG_FIX_INCONSISTENT) == 0) {
@@ -356,11 +358,6 @@ int mail_index_view_sync_begin(struct ma
 		} else {
 			map = view->map;
 		}
-	}
-
-	if (ctx->sync_map_update) {
-		mail_index_sync_map_init(&ctx->sync_map_ctx, view,
-					 MAIL_INDEX_SYNC_HANDLER_VIEW);
 	}
 
 #ifdef DEBUG
@@ -689,8 +686,7 @@ int mail_index_view_sync_commit(struct m
 		view->map->hdr.log_file_tail_offset = 0;
 	}
 
-	if (ctx->sync_map_update)
-		mail_index_sync_map_deinit(&ctx->sync_map_ctx);
+	mail_index_sync_map_deinit(&ctx->sync_map_ctx);
 	mail_index_view_sync_clean_log_syncs(ctx->view);
 
 #ifdef DEBUG


More information about the dovecot-cvs mailing list