[dovecot-cvs] dovecot/src/lib-index mail-index-view-private.h, 1.4, 1.5 mail-index-view-sync.c, 1.9, 1.10 mail-index-view.c, 1.8, 1.9

cras at procontrol.fi cras at procontrol.fi
Sun May 23 19:30:26 EEST 2004


Update of /home/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv4017/lib-index

Modified Files:
	mail-index-view-private.h mail-index-view-sync.c 
	mail-index-view.c 
Log Message:
View's message count shouldn't change until after view is synced.



Index: mail-index-view-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view-private.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- a/mail-index-view-private.h	1 May 2004 14:30:37 -0000	1.4
+++ b/mail-index-view-private.h	23 May 2004 16:30:24 -0000	1.5
@@ -10,6 +10,9 @@
 	unsigned int indexid;
 	struct mail_index_map *map;
 
+	struct mail_index_header tmp_hdr_copy;
+	uint32_t messages_count; /* last synced one, map may be different */
+
 	uint32_t log_file_seq;
 	uoff_t log_file_offset;
         buffer_t *log_syncs;

Index: mail-index-view-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view-sync.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- a/mail-index-view-sync.c	22 May 2004 21:30:42 -0000	1.9
+++ b/mail-index-view-sync.c	23 May 2004 16:30:24 -0000	1.10
@@ -12,7 +12,6 @@
 	enum mail_index_sync_type sync_mask;
 	struct mail_index_map *sync_map;
 	buffer_t *expunges;
-	uint32_t messages_count;
 
 	const struct mail_transaction_header *hdr;
 	const void *data;
@@ -20,6 +19,7 @@
 	size_t data_offset;
 	unsigned int skipped:1;
 	unsigned int last_read:1;
+	unsigned int sync_map_update:1;
 };
 
 static int
@@ -79,7 +79,6 @@
 {
 	const struct mail_index_header *hdr;
 	struct mail_index_view_sync_ctx *ctx;
-	struct mail_index_map *map;
 	enum mail_transaction_type mask;
 	buffer_t *expunges = NULL;
 
@@ -110,20 +109,23 @@
 		return -1;
 	}
 
-	if (sync_mask == MAIL_INDEX_SYNC_MASK_ALL) {
-		map = view->index->map;
-		map->refcount++;
-	} else {
-		map = mail_index_map_to_memory(view->map);
-	}
-	view->syncing = TRUE;
-
 	ctx = i_new(struct mail_index_view_sync_ctx, 1);
 	ctx->view = view;
 	ctx->sync_mask = sync_mask;
-	ctx->sync_map = map;
 	ctx->expunges = expunges;
-	ctx->messages_count = mail_index_view_get_message_count(view);
+
+	if ((sync_mask & MAIL_INDEX_SYNC_TYPE_EXPUNGE) != 0) {
+		ctx->sync_map = view->index->map;
+		ctx->sync_map->refcount++;
+	} else {
+		/* we need a private copy of the map if we don't want to
+		   sync expunges */
+		if (MAIL_INDEX_MAP_IS_IN_MEMORY(view->map))
+			ctx->sync_map_update = TRUE;
+		ctx->sync_map = mail_index_map_to_memory(view->map);
+	}
+
+	view->syncing = TRUE;
 
 	*ctx_r = ctx;
 	return 0;
@@ -254,8 +256,7 @@
 		sync_expunge, sync_append, sync_flag_update, sync_cache_update
 	};
 
-	return mail_transaction_map(ctx->hdr, ctx->data,
-				    &map_funcs, ctx);
+	return mail_transaction_map(ctx->hdr, ctx->data, &map_funcs, ctx);
 }
 
 static int mail_index_view_sync_next_trans(struct mail_index_view_sync_ctx *ctx,
@@ -284,7 +285,7 @@
 	if (view_is_transaction_synced(view, *seq_r, *offset_r))
 		return 0;
 
-	if (ctx->sync_mask != MAIL_INDEX_SYNC_MASK_ALL) {
+	if (ctx->sync_map_update) {
 		if (mail_index_view_sync_map(ctx) < 0)
 			return -1;
 	}
@@ -411,6 +412,9 @@
 	view->map = ctx->sync_map;
 	view->map_protected = FALSE;
 
+	if ((ctx->sync_mask & MAIL_INDEX_SYNC_TYPE_APPEND) != 0)
+		view->messages_count = view->map->records_count;
+
         mail_transaction_log_view_unset(view->log_view);
 
 	if (ctx->expunges != NULL)

Index: mail-index-view.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index-view.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- a/mail-index-view.c	16 May 2004 20:20:24 -0000	1.8
+++ b/mail-index-view.c	23 May 2004 16:30:24 -0000	1.9
@@ -17,6 +17,7 @@
 	view->indexid = index->indexid;
 	view->map = index->map;
 	view->map->refcount++;
+	view->messages_count = view->map->records_count;
 
 	view->log_file_seq = view->map->log_file_seq;
 	view->log_file_offset = view->map->log_file_offset;
@@ -115,7 +116,7 @@
 
 uint32_t mail_index_view_get_message_count(struct mail_index_view *view)
 {
-	return view->map->records_count;
+	return view->messages_count;
 }
 
 int mail_index_view_is_inconsistent(struct mail_index_view *view)
@@ -148,7 +149,14 @@
 	if (mail_index_view_lock(view) < 0)
 		return -1;
 
-	*hdr_r = view->map->hdr;
+	if (view->map->hdr->messages_count == view->messages_count)
+		*hdr_r = view->map->hdr;
+	else {
+		/* messages_count differs, use a modified copy */
+		view->tmp_hdr_copy = *view->map->hdr;
+		view->tmp_hdr_copy.messages_count = view->messages_count;
+		*hdr_r = &view->tmp_hdr_copy;
+	}
 	return 0;
 }
 
@@ -160,7 +168,7 @@
 	uint32_t uid;
 
 	i_assert(seq > 0);
-	i_assert(seq <= view->map->records_count);
+	i_assert(seq <= view->messages_count);
 
 	if (mail_index_view_lock(view) < 0)
 		return -1;
@@ -195,7 +203,7 @@
 			  uint32_t *uid_r)
 {
 	i_assert(seq > 0);
-	i_assert(seq <= view->map->records_count);
+	i_assert(seq <= view->messages_count);
 
 	if (mail_index_view_lock(view) < 0)
 		return -1;
@@ -214,7 +222,7 @@
 	rec = view->map->records;
 
 	idx = left_idx = *left_idx_p;
-	right_idx = view->map->records_count;
+	right_idx = view->messages_count;
 
 	while (left_idx < right_idx) {
 		idx = (left_idx + right_idx) / 2;
@@ -227,7 +235,7 @@
 			break;
 	}
 
-	if (idx == view->map->records_count) {
+	if (idx == view->messages_count) {
 		/* no messages available */
 		return 0;
 	}
@@ -237,7 +245,7 @@
 		if (nearest_side > 0) {
 			/* we want uid or larger */
 			return rec[idx].uid > uid ? idx+1 :
-				idx == view->map->records_count-1 ? 0 : idx+2;
+				idx == view->messages_count-1 ? 0 : idx+2;
 		} else {
 			/* we want uid or smaller */
 			return rec[idx].uid < uid ? idx + 1 : idx;
@@ -313,7 +321,7 @@
 	}
 
 	rec = &view->map->records[seq-1];
-	for (; seq <= view->map->records_count; seq++, rec++) {
+	for (; seq <= view->messages_count; seq++, rec++) {
 		if ((rec->flags & flags_mask) == (uint8_t)flags) {
 			*seq_r = seq;
 			break;



More information about the dovecot-cvs mailing list