changeset 5779:b25c9ca2142b HEAD

mail_index_sync_begin() takes now flags parameter instead of two booleans. Cleanups to recent handling.
author Timo Sirainen <tss@iki.fi>
date Tue, 19 Jun 2007 16:33:05 +0300
parents 3d4344ad057c
children f61313136530
files src/lib-index/mail-index-sync-update.c src/lib-index/mail-index-sync.c src/lib-index/mail-index.h src/lib-index/mailbox-list-index-sync.c src/lib-storage/index/cydir/cydir-sync.c src/lib-storage/index/dbox/dbox-save.c src/lib-storage/index/dbox/dbox-sync.c src/lib-storage/index/maildir/maildir-sync.c src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/list/index-mailbox-list-sync.c
diffstat 10 files changed, 42 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync-update.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-index/mail-index-sync-update.c	Tue Jun 19 16:33:05 2007 +0300
@@ -639,26 +639,6 @@
 	mail_index_sync_deinit_handlers(sync_map_ctx);
 }
 
-static void mail_index_sync_remove_recent(struct mail_index_sync_map_ctx *ctx)
-{
-	struct mail_index_map *map = ctx->view->map;
-	struct mail_index_record *rec;
-	unsigned int i;
-
-	for (i = 0; i < map->records_count; i++) {
-		rec = MAIL_INDEX_MAP_IDX(map, i);
-		if ((rec->flags & MAIL_RECENT) != 0) {
-			rec->flags &= ~MAIL_RECENT;
-
-			mail_index_sync_write_seq_update(ctx, i + 1, i + 1);
-		}
-	}
-
-	map->hdr.recent_messages_count = 0;
-	map->hdr.first_recent_uid_lowwater = map->hdr.next_uid;
-	map->write_base_header = TRUE;
-}
-
 static void mail_index_sync_update_hdr_dirty_flag(struct mail_index_map *map)
 {
 	const struct mail_index_record *rec;
--- a/src/lib-index/mail-index-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -28,8 +28,6 @@
 	unsigned int lock_id;
 
 	unsigned int sync_appends:1;
-	unsigned int sync_recent:1;
-	unsigned int sync_dirty:1;
 };
 
 static void mail_index_sync_add_expunge(struct mail_index_sync_ctx *ctx)
@@ -192,12 +190,6 @@
 		}
 	}
 
-	if (!seen_recent) {
-		/* no recent messages, drop the sync_recent flag so we
-		   don't scan through the messages again */
-		ctx->sync_recent = FALSE;
-	}
-
 	return 0;
 }
 
@@ -215,7 +207,8 @@
 }
 
 static int
-mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx)
+mail_index_sync_read_and_sort(struct mail_index_sync_ctx *ctx,
+			      enum mail_index_sync_flags flags)
 {
 	struct mail_index_transaction *sync_trans = ctx->sync_trans;
 	struct mail_index_sync_list *synclist;
@@ -224,13 +217,13 @@
 	int ret;
 
 	if ((ctx->view->map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) &&
-	    ctx->sync_dirty) {
+	    (flags & MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY) != 0) {
 		/* show dirty flags as flag updates */
 		if (mail_index_sync_add_dirty_updates(ctx) < 0)
 			return -1;
 	}
 
-	if (ctx->sync_recent) {
+	if ((flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0) {
 		if (mail_index_sync_add_recent_updates(ctx) < 0)
 			return -1;
 	}
@@ -292,11 +285,12 @@
 
 static bool
 mail_index_need_sync(struct mail_index *index,
-		     const struct mail_index_header *hdr, bool sync_recent,
+		     const struct mail_index_header *hdr,
+		     enum mail_index_sync_flags flags,
 		     uint32_t log_file_seq, uoff_t log_file_offset)
 {
-	// FIXME: how's this recent syncing supposed to work?
-	if (sync_recent && hdr->recent_messages_count > 0)
+	if (hdr->recent_messages_count > 0 &&
+	    (flags & MAIL_INDEX_SYNC_FLAG_DROP_RECENT) != 0)
 		return TRUE;
 
 	if (hdr->log_file_seq < log_file_seq ||
@@ -338,7 +332,7 @@
 			  struct mail_index_view **view_r,
 			  struct mail_index_transaction **trans_r,
 			  uint32_t log_file_seq, uoff_t log_file_offset,
-			  bool sync_recent, bool sync_dirty)
+			  enum mail_index_sync_flags flags)
 {
 	const struct mail_index_header *hdr;
 	struct mail_index_sync_ctx *ctx;
@@ -365,7 +359,7 @@
 	}
 	hdr = &index->map->hdr;
 
-	if (!mail_index_need_sync(index, hdr, sync_recent,
+	if (!mail_index_need_sync(index, hdr, flags,
 				  log_file_seq, log_file_offset)) {
 		mail_index_unlock(index, lock_id);
 		mail_transaction_log_sync_unlock(index->log);
@@ -389,8 +383,6 @@
 	ctx = i_new(struct mail_index_sync_ctx, 1);
 	ctx->index = index;
 	ctx->lock_id = lock_id;
-	ctx->sync_recent = sync_recent;
-	ctx->sync_dirty = sync_dirty;
 	ctx->last_tail_seq = hdr->log_file_seq;
 	ctx->last_tail_offset = hdr->log_file_tail_offset;
 
@@ -410,7 +402,7 @@
 
 	/* we need to have all the transactions sorted to optimize
 	   caller's mailbox access patterns */
-	if (mail_index_sync_read_and_sort(ctx) < 0) {
+	if (mail_index_sync_read_and_sort(ctx, flags) < 0) {
                 mail_index_sync_rollback(&ctx);
 		return -1;
 	}
--- a/src/lib-index/mail-index.h	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-index/mail-index.h	Tue Jun 19 16:33:05 2007 +0300
@@ -107,6 +107,13 @@
 	MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET	= 0x20
 };
 
+enum mail_index_sync_flags {
+	/* Resync all dirty messages' flags. */
+	MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY	= 0x01,
+	/* Drop recent flags from all messages */
+	MAIL_INDEX_SYNC_FLAG_DROP_RECENT	= 0x02
+};
+
 enum mail_index_view_sync_flags {
 	/* Don't sync expunges */
 	MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES	= 0x01
@@ -234,7 +241,7 @@
 			  struct mail_index_view **view_r,
 			  struct mail_index_transaction **trans_r,
 			  uint32_t log_file_seq, uoff_t log_file_offset,
-			  bool sync_recent, bool sync_dirty);
+			  enum mail_index_sync_flags flags);
 /* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
 int mail_index_sync_next(struct mail_index_sync_ctx *ctx,
 			 struct mail_index_sync_rec *sync_rec);
--- a/src/lib-index/mailbox-list-index-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-index/mailbox-list-index-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -333,7 +333,7 @@
 
 	if (mail_index_sync_begin(ctx->index->mail_index, &ctx->mail_sync_ctx,
 				  &ctx->mail_view, &ctx->trans, (uint32_t)-1, 0,
-				  FALSE, FALSE) < 0)
+				  0) < 0)
 		return -1;
 
 	/* we should have only external transactions in here, for which we
--- a/src/lib-storage/index/cydir/cydir-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -117,14 +117,19 @@
 		     struct cydir_sync_context **ctx_r)
 {
 	struct cydir_sync_context *ctx;
+	enum mail_index_sync_flags sync_flags;
 	int ret;
 
 	ctx = i_new(struct cydir_sync_context, 1);
 	ctx->mbox = mbox;
+
+	sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY;
+	if (!mbox->ibox.keep_recent)
+		sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
+
 	ret = mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
 				    &ctx->sync_view, &ctx->trans,
-				    (uint32_t)-1, (uoff_t)-1,
-				    !mbox->ibox.keep_recent, TRUE);
+				    (uint32_t)-1, (uoff_t)-1, sync_flags);
 	if (ret <= 0) {
 		if (ret < 0)
 			mail_storage_set_index_error(&mbox->ibox);
--- a/src/lib-storage/index/dbox/dbox-save.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-save.c	Tue Jun 19 16:33:05 2007 +0300
@@ -373,7 +373,7 @@
 	/* lock index lock before dropping uidlist lock in _append_commit() */
 	if (mail_index_sync_begin(ctx->mbox->ibox.index, &ctx->index_sync_ctx,
 				  &view, &ctx->trans, (uint32_t)-1, (uoff_t)-1,
-				  FALSE, FALSE) < 0) {
+				  0) < 0) {
 		ctx->failed = TRUE;
 		dbox_transaction_save_rollback(ctx);
 		return -1;
--- a/src/lib-storage/index/dbox/dbox-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -486,6 +486,7 @@
 			  struct dbox_sync_context *ctx, bool *force)
 {
 	const struct mail_index_header *hdr;
+	enum mail_index_sync_flags sync_flags;
 	time_t mtime;
 	int ret;
 
@@ -497,10 +498,12 @@
 				   &mtime) < 0)
 		return -1;
 
+	sync_flags = MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY;
+	if (!mbox->ibox.keep_recent)
+		sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
 	ret = mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
 				    &ctx->sync_view, &ctx->trans,
-				    (uint32_t)-1, (uoff_t)-1,
-				    !mbox->ibox.keep_recent, TRUE);
+				    (uint32_t)-1, (uoff_t)-1, sync_flags);
 	if (ret <= 0) {
 		if (ret < 0)
 			mail_storage_set_index_error(&mbox->ibox);
--- a/src/lib-storage/index/maildir/maildir-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -1009,8 +1009,7 @@
 	struct mail_index_transaction *trans;
 
 	if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx, &view, &trans,
-				  (uint32_t)-1, (uoff_t)-1,
-				  FALSE, FALSE) <= 0) {
+				  (uint32_t)-1, (uoff_t)-1, 0) <= 0) {
 		mail_storage_set_index_error(&mbox->ibox);
 		return -1;
 	}
--- a/src/lib-storage/index/mbox/mbox-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -1695,6 +1695,7 @@
 	struct mail_index_view *sync_view;
 	struct mail_index_transaction *trans;
 	struct mbox_sync_context sync_ctx;
+	enum mail_index_sync_flags sync_flags;
 	uint32_t seq;
 	uoff_t offset;
 	unsigned int lock_id = 0;
@@ -1760,10 +1761,14 @@
 		offset = (uoff_t)-1;
 	}
 
+	sync_flags = 0;
+	if (!mbox->ibox.keep_recent)
+		sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
+	if ((flags & MBOX_SYNC_REWRITE) != 0)
+		sync_flags |= MAIL_INDEX_SYNC_FLAG_FLUSH_DIRTY;
 	ret = mail_index_sync_begin(mbox->ibox.index, &index_sync_ctx,
 				    &sync_view, &trans, seq, offset,
-				    !mbox->ibox.keep_recent,
-				    (flags & MBOX_SYNC_REWRITE) != 0);
+				    sync_flags);
 	if (ret <= 0) {
 		if (ret < 0)
 			mail_storage_set_index_error(&mbox->ibox);
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Tue Jun 19 16:20:19 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Tue Jun 19 16:33:05 2007 +0300
@@ -69,8 +69,7 @@
 
 	ret = mail_index_sync_begin(ilist->mail_index,
 				    &mail_sync_ctx, &view, &trans,
-				    ibox->log_seq, ibox->log_offset,
-				    FALSE, FALSE);
+				    ibox->log_seq, ibox->log_offset, 0);
 	if (ret <= 0)
 		return ret;