dovecot: mail_index_view_sync_next() and mailbox_sync_next() ret...

dovecot at dovecot.org dovecot at dovecot.org
Sun Aug 12 19:41:34 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/f52e7d1402b5
changeset: 6279:f52e7d1402b5
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Aug 12 18:16:40 2007 +0300
description:
mail_index_view_sync_next() and mailbox_sync_next() returns now bool.
Renamed void mailbox_index_view_sync_end() to int
mailbox_index_view_sync_commit().

diffstat:

14 files changed, 45 insertions(+), 46 deletions(-)
src/deliver/deliver.c                          |    2 +-
src/imap/imap-sync.c                           |   12 ++++--------
src/lib-index/mail-index-view-sync.c           |   19 +++++++++++++------
src/lib-index/mail-index.h                     |    7 +++----
src/lib-storage/index/index-storage.h          |    4 ++--
src/lib-storage/index/index-sync.c             |   21 +++++++++------------
src/lib-storage/list/index-mailbox-list-sync.c |    6 +++---
src/lib-storage/mail-storage-private.h         |    4 ++--
src/lib-storage/mail-storage.c                 |    4 ++--
src/lib-storage/mail-storage.h                 |    4 ++--
src/plugins/convert/convert-storage.c          |    2 +-
src/plugins/mbox-snarf/mbox-snarf-plugin.c     |    2 +-
src/plugins/trash/trash-plugin.c               |    2 +-
src/pop3/client.c                              |    2 +-

diffs (truncated from 307 to 300 lines):

diff -r ce83635191d4 -r f52e7d1402b5 src/deliver/deliver.c
--- a/src/deliver/deliver.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/deliver/deliver.c	Sun Aug 12 18:16:40 2007 +0300
@@ -75,7 +75,7 @@ static int sync_quick(struct mailbox *bo
         struct mailbox_sync_rec sync_rec;
 
 	ctx = mailbox_sync_init(box, 0);
-	while (mailbox_sync_next(ctx, &sync_rec) > 0)
+	while (mailbox_sync_next(ctx, &sync_rec))
 		;
 	return mailbox_sync_deinit(&ctx, 0, NULL);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/imap/imap-sync.c
--- a/src/imap/imap-sync.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/imap/imap-sync.c	Sun Aug 12 18:16:40 2007 +0300
@@ -113,13 +113,9 @@ int imap_sync_more(struct imap_sync_cont
 	for (;;) {
 		if (ctx->seq == 0) {
 			/* get next one */
-			ret = mailbox_sync_next(ctx->sync_ctx,
-						&ctx->sync_rec);
-			if (ret <= 0) {
-				if (ret == 0) {
-					/* all finished ok */
-					ret = 1;
-				}
+			if (!mailbox_sync_next(ctx->sync_ctx, &ctx->sync_rec)) {
+				/* finished */
+				ret = 1;
 				break;
 			}
 		}
@@ -199,7 +195,7 @@ int imap_sync_nonselected(struct mailbox
         struct mailbox_sync_rec sync_rec;
 
 	ctx = mailbox_sync_init(box, flags);
-	while (mailbox_sync_next(ctx, &sync_rec) > 0)
+	while (mailbox_sync_next(ctx, &sync_rec))
 		;
 	return mailbox_sync_deinit(&ctx, 0, NULL);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-index/mail-index-view-sync.c
--- a/src/lib-index/mail-index-view-sync.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-index/mail-index-view-sync.c	Sun Aug 12 18:16:40 2007 +0300
@@ -19,6 +19,7 @@ struct mail_index_view_sync_ctx {
 	const void *data;
 
 	size_t data_offset;
+	unsigned int failed:1;
 	unsigned int sync_map_update:1;
 	unsigned int skipped_expunges:1;
 	unsigned int last_read:1;
@@ -556,22 +557,25 @@ mail_index_view_sync_get_rec(struct mail
 	return TRUE;
 }
 
-int mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
-			      struct mail_index_view_sync_rec *sync_rec)
+bool mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
+			       struct mail_index_view_sync_rec *sync_rec)
 {
 	int ret;
 
 	do {
 		if (ctx->hdr == NULL || ctx->data_offset == ctx->hdr->size) {
 			ret = mail_index_view_sync_get_next_transaction(ctx);
-			if (ret <= 0)
-				return ret;
+			if (ret <= 0) {
+				if (ret < 0)
+					ctx->failed = TRUE;
+				return FALSE;
+			}
 
 			ctx->data_offset = 0;
 		}
 	} while (!mail_index_view_sync_get_rec(ctx, sync_rec));
 
-	return 1;
+	return TRUE;
 }
 
 void mail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
@@ -602,10 +606,11 @@ mail_index_view_sync_clean_log_syncs(str
 		array_delete(&view->syncs_hidden, 0, i);
 }
 
-void mail_index_view_sync_end(struct mail_index_view_sync_ctx **_ctx)
+int mail_index_view_sync_commit(struct mail_index_view_sync_ctx **_ctx)
 {
         struct mail_index_view_sync_ctx *ctx = *_ctx;
         struct mail_index_view *view = ctx->view;
+	int ret = ctx->failed ? -1 : 0;
 
 	i_assert(view->syncing);
 
@@ -614,6 +619,7 @@ void mail_index_view_sync_end(struct mai
 	if (!ctx->last_read) {
 		/* we didn't sync everything */
 		view->inconsistent = TRUE;
+		ret = -1;
 	}
 
 	if (view->sync_new_map != NULL) {
@@ -652,6 +658,7 @@ void mail_index_view_sync_end(struct mai
 
 	view->syncing = FALSE;
 	i_free(ctx);
+	return ret;
 }
 
 void mail_index_view_add_hidden_transaction(struct mail_index_view *view,
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-index/mail-index.h	Sun Aug 12 18:16:40 2007 +0300
@@ -284,13 +284,12 @@ int mail_index_view_sync_begin(struct ma
 int mail_index_view_sync_begin(struct mail_index_view *view,
                                enum mail_index_view_sync_flags flags,
 			       struct mail_index_view_sync_ctx **ctx_r);
-/* Returns -1 if error, 0 if sync is finished, 1 if record was filled. */
-int mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
-			      struct mail_index_view_sync_rec *sync_rec);
+bool mail_index_view_sync_next(struct mail_index_view_sync_ctx *ctx,
+			       struct mail_index_view_sync_rec *sync_rec);
 void
 mail_index_view_sync_get_expunges(struct mail_index_view_sync_ctx *ctx,
 				  const ARRAY_TYPE(seq_range) **expunges_r);
-void mail_index_view_sync_end(struct mail_index_view_sync_ctx **ctx);
+int mail_index_view_sync_commit(struct mail_index_view_sync_ctx **ctx);
 
 /* Returns the index header. */
 const struct mail_index_header *
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-storage/index/index-storage.h	Sun Aug 12 18:16:40 2007 +0300
@@ -129,8 +129,8 @@ struct mailbox_sync_context *
 struct mailbox_sync_context *
 index_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags,
 			bool failed);
-int index_mailbox_sync_next(struct mailbox_sync_context *ctx,
-			    struct mailbox_sync_rec *sync_rec_r);
+bool index_mailbox_sync_next(struct mailbox_sync_context *ctx,
+			     struct mailbox_sync_rec *sync_rec_r);
 int index_mailbox_sync_deinit(struct mailbox_sync_context *ctx,
 			      enum mailbox_status_items status_items,
 			      struct mailbox_status *status_r);
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-storage/index/index-sync.c
--- a/src/lib-storage/index/index-sync.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-storage/index/index-sync.c	Sun Aug 12 18:16:40 2007 +0300
@@ -179,18 +179,17 @@ static bool sync_rec_check_skips(struct 
 	return TRUE;
 }
 
-int index_mailbox_sync_next(struct mailbox_sync_context *_ctx,
-			    struct mailbox_sync_rec *sync_rec_r)
+bool index_mailbox_sync_next(struct mailbox_sync_context *_ctx,
+			     struct mailbox_sync_rec *sync_rec_r)
 {
 	struct index_mailbox_sync_context *ctx =
 		(struct index_mailbox_sync_context *)_ctx;
 	struct mail_index_view_sync_rec sync;
-	int ret;
 
 	if (ctx->failed)
-		return -1;
-
-	while ((ret = mail_index_view_sync_next(ctx->sync_ctx, &sync)) > 0) {
+		return FALSE;
+
+	while (mail_index_view_sync_next(ctx->sync_ctx, &sync)) {
 		switch (sync.type) {
 		case MAIL_INDEX_SYNC_TYPE_APPEND:
 			/* not interested */
@@ -220,10 +219,6 @@ int index_mailbox_sync_next(struct mailb
 			return 1;
 		}
 	}
-	if (ret < 0) {
-		mail_storage_set_index_error(ctx->ibox);
-		return -1;
-	}
 
 	if (ctx->expunge_pos > 0) {
 		/* expunges is a sorted array of sequences. it's easiest for
@@ -316,8 +311,10 @@ int index_mailbox_sync_deinit(struct mai
 	uint32_t seq1, seq2;
 	int ret = ctx->failed ? -1 : 0;
 
-	if (ctx->sync_ctx != NULL)
-		mail_index_view_sync_end(&ctx->sync_ctx);
+	if (ctx->sync_ctx != NULL) {
+		if (mail_index_view_sync_commit(&ctx->sync_ctx) < 0)
+			ret = -1;
+	}
 	index_mailbox_expunge_unseen_recent(ctx);
 
 	if (ibox->keep_recent) {
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-storage/list/index-mailbox-list-sync.c
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Sun Aug 12 18:16:40 2007 +0300
@@ -296,13 +296,13 @@ index_list_sync_init(struct mailbox *box
 	return ibox->module_ctx.super.sync_init(box, flags);
 }
 
-static int index_list_sync_next(struct mailbox_sync_context *ctx,
-				struct mailbox_sync_rec *sync_rec_r)
+static bool index_list_sync_next(struct mailbox_sync_context *ctx,
+				 struct mailbox_sync_rec *sync_rec_r)
 {
 	struct index_list_mailbox *ibox = INDEX_LIST_STORAGE_CONTEXT(ctx->box);
 
 	if (!ctx->box->opened)
-		return 0;
+		return FALSE;
 
 	return ibox->module_ctx.super.sync_next(ctx, sync_rec_r);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-storage/mail-storage-private.h	Sun Aug 12 18:16:40 2007 +0300
@@ -92,8 +92,8 @@ struct mailbox_vfuncs {
 	struct mailbox_sync_context *
 		(*sync_init)(struct mailbox *box,
 			     enum mailbox_sync_flags flags);
-	int (*sync_next)(struct mailbox_sync_context *ctx,
-			 struct mailbox_sync_rec *sync_rec_r);
+	bool (*sync_next)(struct mailbox_sync_context *ctx,
+			  struct mailbox_sync_rec *sync_rec_r);
 	int (*sync_deinit)(struct mailbox_sync_context *ctx,
 			   enum mailbox_status_items status_items,
 			   struct mailbox_status *status_r);
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-storage/mail-storage.c	Sun Aug 12 18:16:40 2007 +0300
@@ -498,8 +498,8 @@ mailbox_sync_init(struct mailbox *box, e
 	return box->v.sync_init(box, flags);
 }
 
-int mailbox_sync_next(struct mailbox_sync_context *ctx,
-		      struct mailbox_sync_rec *sync_rec_r)
+bool mailbox_sync_next(struct mailbox_sync_context *ctx,
+		       struct mailbox_sync_rec *sync_rec_r)
 {
 	return ctx->box->v.sync_next(ctx, sync_rec_r);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/lib-storage/mail-storage.h	Sun Aug 12 18:16:40 2007 +0300
@@ -285,8 +285,8 @@ void mailbox_get_status(struct mailbox *
 /* Synchronize the mailbox. */
 struct mailbox_sync_context *
 mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);
-int mailbox_sync_next(struct mailbox_sync_context *ctx,
-		      struct mailbox_sync_rec *sync_rec_r);
+bool mailbox_sync_next(struct mailbox_sync_context *ctx,
+		       struct mailbox_sync_rec *sync_rec_r);
 int mailbox_sync_deinit(struct mailbox_sync_context **ctx,
 			enum mailbox_status_items status_items,
 			struct mailbox_status *status_r);
diff -r ce83635191d4 -r f52e7d1402b5 src/plugins/convert/convert-storage.c
--- a/src/plugins/convert/convert-storage.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/plugins/convert/convert-storage.c	Sun Aug 12 18:16:40 2007 +0300
@@ -31,7 +31,7 @@ static int sync_mailbox(struct mailbox *
         struct mailbox_sync_rec sync_rec;
 
 	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec) > 0)
+	while (mailbox_sync_next(ctx, &sync_rec))
 		;
 	return mailbox_sync_deinit(&ctx, 0, NULL);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/plugins/mbox-snarf/mbox-snarf-plugin.c
--- a/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/plugins/mbox-snarf/mbox-snarf-plugin.c	Sun Aug 12 18:16:40 2007 +0300
@@ -41,7 +41,7 @@ static int sync_mailbox(struct mailbox *
         struct mailbox_sync_rec sync_rec;
 
 	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec) > 0)
+	while (mailbox_sync_next(ctx, &sync_rec))
 		;
 	return mailbox_sync_deinit(&ctx, 0, NULL);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/plugins/trash/trash-plugin.c
--- a/src/plugins/trash/trash-plugin.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/plugins/trash/trash-plugin.c	Sun Aug 12 18:16:40 2007 +0300
@@ -48,7 +48,7 @@ static int sync_mailbox(struct mailbox *
         struct mailbox_sync_rec sync_rec;
 
 	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
-	while (mailbox_sync_next(ctx, &sync_rec) > 0)
+	while (mailbox_sync_next(ctx, &sync_rec))
 		;
 	return mailbox_sync_deinit(&ctx, 0, NULL);
 }
diff -r ce83635191d4 -r f52e7d1402b5 src/pop3/client.c
--- a/src/pop3/client.c	Sun Aug 12 18:07:22 2007 +0300
+++ b/src/pop3/client.c	Sun Aug 12 18:16:40 2007 +0300
@@ -44,7 +44,7 @@ static int sync_mailbox(struct mailbox *
         struct mailbox_sync_rec sync_rec;


More information about the dovecot-cvs mailing list