changeset 6332:aa4a78b3c626 HEAD

Renamed mail_index_sync_begin() to mail_index_sync_begin_to() and added a new mail_index_sync_begin() without seq/offset parameters.
author Timo Sirainen <tss@iki.fi>
date Wed, 29 Aug 2007 22:58:27 +0300
parents 081fd0acddd2
children d815c115ade6
files 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-index.c src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/list/index-mailbox-list-sync.c
diffstat 9 files changed, 59 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Wed Aug 29 22:58:27 2007 +0300
@@ -296,12 +296,26 @@
 }
 
 int mail_index_sync_begin(struct mail_index *index,
-                          struct mail_index_sync_ctx **ctx_r,
+			  struct mail_index_sync_ctx **ctx_r,
 			  struct mail_index_view **view_r,
 			  struct mail_index_transaction **trans_r,
-			  uint32_t log_file_seq, uoff_t log_file_offset,
 			  enum mail_index_sync_flags flags)
 {
+	int ret;
+
+	ret = mail_index_sync_begin_to(index, ctx_r, view_r, trans_r,
+				       (uint32_t)-1, (uoff_t)-1, flags);
+	i_assert(ret != 0);
+	return ret <= 0 ? -1 : 0;
+}
+
+int mail_index_sync_begin_to(struct mail_index *index,
+			     struct mail_index_sync_ctx **ctx_r,
+			     struct mail_index_view **view_r,
+			     struct mail_index_transaction **trans_r,
+			     uint32_t log_file_seq, uoff_t log_file_offset,
+			     enum mail_index_sync_flags flags)
+{
 	const struct mail_index_header *hdr;
 	struct mail_index_sync_ctx *ctx;
 	struct mail_index_view *sync_view;
@@ -376,9 +390,9 @@
 			mail_transaction_log_sync_unlock(index->log);
 			return -1;
 		}
-		return mail_index_sync_begin(index, ctx_r, view_r, trans_r,
-					     log_file_seq, log_file_offset,
-					     flags);
+		return mail_index_sync_begin_to(index, ctx_r, view_r, trans_r,
+						log_file_seq, log_file_offset,
+						flags);
 	}
 
 	/* we need to have all the transactions sorted to optimize
--- a/src/lib-index/mail-index.h	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-index/mail-index.h	Wed Aug 29 22:58:27 2007 +0300
@@ -224,12 +224,7 @@
 struct mail_index_view *
 mail_index_transaction_open_updated_view(struct mail_index_transaction *t);
 
-/* Begin synchronizing mailbox with index file. Returns 1 if ok, -1 if error.
-
-   If log_file_seq is not (uint32_t)-1 and index is already synchronized up
-   to the given log_file_offset, the synchronization isn't started and this
-   function returns 0. This should be done when you wish to sync your committed
-   transaction instead of doing a full mailbox synchronization.
+/* Begin synchronizing mailbox with index file. Returns 0 if ok, -1 if error.
 
    mail_index_sync_next() returns all changes from previously committed
    transactions which haven't yet been committed to the actual mailbox.
@@ -255,8 +250,18 @@
 			  struct mail_index_sync_ctx **ctx_r,
 			  struct mail_index_view **view_r,
 			  struct mail_index_transaction **trans_r,
-			  uint32_t log_file_seq, uoff_t log_file_offset,
 			  enum mail_index_sync_flags flags);
+/* Like mail_index_sync_begin(), but returns 1 if OK and if index is already
+   synchronized up to the given log_file_seq+offset, the synchronization isn't
+   started and this function returns 0. This should be done when you wish to
+   sync your committed transaction instead of doing a full mailbox
+   synchronization. */
+int mail_index_sync_begin_to(struct mail_index *index,
+			     struct mail_index_sync_ctx **ctx_r,
+			     struct mail_index_view **view_r,
+			     struct mail_index_transaction **trans_r,
+			     uint32_t log_file_seq, uoff_t log_file_offset,
+			     enum mail_index_sync_flags flags);
 /* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
 bool 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	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-index/mailbox-list-index-sync.c	Wed Aug 29 22:58:27 2007 +0300
@@ -360,7 +360,7 @@
 	struct mail_index_sync_rec sync_rec;
 
 	if (mail_index_sync_begin(ctx->index->mail_index, &ctx->mail_sync_ctx,
-				  &ctx->mail_view, &ctx->trans, (uint32_t)-1, 0,
+				  &ctx->mail_view, &ctx->trans,
 				  MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES) < 0)
 		return -1;
 
--- a/src/lib-storage/index/cydir/cydir-sync.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-sync.c	Wed Aug 29 22:58:27 2007 +0300
@@ -114,7 +114,6 @@
 {
 	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;
@@ -123,14 +122,12 @@
 	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, sync_flags);
-	if (ret <= 0) {
-		if (ret < 0)
-			mail_storage_set_index_error(&mbox->ibox);
+	if (mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
+				  &ctx->sync_view, &ctx->trans,
+				  sync_flags) < 0) {
+		mail_storage_set_index_error(&mbox->ibox);
 		i_free(ctx);
-		return ret;
+		return -1;
 	}
 
 	cydir_sync_index(ctx);
--- a/src/lib-storage/index/dbox/dbox-save.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-save.c	Wed Aug 29 22:58:27 2007 +0300
@@ -371,8 +371,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,
-				  0) < 0) {
+				  &view, &ctx->trans, 0) < 0) {
 		ctx->failed = TRUE;
 		dbox_transaction_save_rollback(ctx);
 		return -1;
--- a/src/lib-storage/index/dbox/dbox-sync.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync.c	Wed Aug 29 22:58:27 2007 +0300
@@ -455,7 +455,6 @@
 	const struct mail_index_header *hdr;
 	enum mail_index_sync_flags sync_flags;
 	time_t mtime;
-	int ret;
 
 	memset(ctx, 0, sizeof(*ctx));
 	ctx->mbox = mbox;
@@ -468,14 +467,12 @@
 	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, sync_flags);
-	if (ret <= 0) {
-		if (ret < 0)
-			mail_storage_set_index_error(&mbox->ibox);
+	if (mail_index_sync_begin(mbox->ibox.index, &ctx->index_sync_ctx,
+				  &ctx->sync_view, &ctx->trans,
+				  sync_flags) < 0) {
+		mail_storage_set_index_error(&mbox->ibox);
 		dbox_uidlist_sync_rollback(ctx->uidlist_sync_ctx);
-		return ret;
+		return -1;
 	}
 
 	hdr = mail_index_get_header(ctx->sync_view);
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Wed Aug 29 22:58:27 2007 +0300
@@ -162,7 +162,7 @@
 		sync_flags |= MAIL_INDEX_SYNC_FLAG_DROP_RECENT;
 
 	if (mail_index_sync_begin(mbox->ibox.index, &sync_ctx, &view, &trans,
-				  (uint32_t)-1, (uoff_t)-1, sync_flags) <= 0) {
+				  sync_flags) < 0) {
 		mail_storage_set_index_error(&mbox->ibox);
 		return -1;
 	}
--- a/src/lib-storage/index/mbox/mbox-sync.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Wed Aug 29 22:58:27 2007 +0300
@@ -1539,8 +1539,6 @@
 	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;
 	int ret, changed;
 	bool delay_writes;
@@ -1605,22 +1603,23 @@
 		}
 	}
 
-	if ((flags & MBOX_SYNC_LAST_COMMIT) != 0) {
-		seq = mbox->ibox.commit_log_file_seq;
-		offset = mbox->ibox.commit_log_file_offset;
-	} else {
-		seq = (uint32_t)-1;
-		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,
-				    sync_flags);
+
+	if ((flags & MBOX_SYNC_LAST_COMMIT) != 0) {
+		ret = mail_index_sync_begin_to(mbox->ibox.index,
+				&index_sync_ctx, &sync_view, &trans,
+				mbox->ibox.commit_log_file_seq,
+				mbox->ibox.commit_log_file_offset, sync_flags);
+	} else {
+		ret = mail_index_sync_begin(mbox->ibox.index, &index_sync_ctx,
+					    &sync_view, &trans,
+					    sync_flags) < 0 ? -1 : 1;
+	}
+
 	if (ret <= 0) {
 		if (ret < 0)
 			mail_storage_set_index_error(&mbox->ibox);
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Mon Aug 27 19:34:17 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Wed Aug 29 22:58:27 2007 +0300
@@ -67,9 +67,9 @@
 	if (ibox->log_seq == 0)
 		return 0;
 
-	ret = mail_index_sync_begin(ilist->mail_index,
-				    &mail_sync_ctx, &view, &trans,
-				    ibox->log_seq, ibox->log_offset, 0);
+	ret = mail_index_sync_begin_to(ilist->mail_index,
+				       &mail_sync_ctx, &view, &trans,
+				       ibox->log_seq, ibox->log_offset, 0);
 	if (ret <= 0)
 		return ret;