dovecot: mail_index_sync_next() can't fail anymore.

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


details:   http://hg.dovecot.org/dovecot/rev/ce83635191d4
changeset: 6278:ce83635191d4
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Aug 12 18:07:22 2007 +0300
description:
mail_index_sync_next() can't fail anymore.

diffstat:

10 files changed, 27 insertions(+), 60 deletions(-)
src/lib-index/mail-index-sync.c                    |   10 +++++-----
src/lib-index/mail-index.h                         |    4 ++--
src/lib-index/mailbox-list-index-sync.c            |    2 +-
src/lib-storage/index/cydir/cydir-sync.c           |   15 +++------------
src/lib-storage/index/dbox/dbox-sync.c             |    8 ++------
src/lib-storage/index/index-sync-changes.c         |   15 +++------------
src/lib-storage/index/index-sync-changes.h         |    4 ++--
src/lib-storage/index/maildir/maildir-sync-index.c |    7 +------
src/lib-storage/index/mbox/mbox-sync.c             |   20 +++++++-------------
src/lib-storage/list/index-mailbox-list-sync.c     |    2 +-

diffs (270 lines):

diff -r 5f66277bbe40 -r ce83635191d4 src/lib-index/mail-index-sync.c
--- a/src/lib-index/mail-index-sync.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Sun Aug 12 18:07:22 2007 +0300
@@ -445,8 +445,8 @@ static void mail_index_sync_get_keyword_
 	rec->uid2 = range->uid2;
 }
 
-int mail_index_sync_next(struct mail_index_sync_ctx *ctx,
-			 struct mail_index_sync_rec *sync_rec)
+bool mail_index_sync_next(struct mail_index_sync_ctx *ctx,
+			  struct mail_index_sync_rec *sync_rec)
 {
 	struct mail_index_transaction *sync_trans = ctx->sync_trans;
 	struct mail_index_sync_list *sync_list;
@@ -485,9 +485,9 @@ int mail_index_sync_next(struct mail_ind
 				sync_rec->type = MAIL_INDEX_SYNC_TYPE_APPEND;
 				sync_rec->uid1 = ctx->append_uid_first;
 				sync_rec->uid2 = ctx->append_uid_last;
-				return 1;
+				return TRUE;
 			}
-			return 0;
+			return FALSE;
 		}
                 ctx->next_uid = next_found_uid;
 		i = next_i;
@@ -507,7 +507,7 @@ int mail_index_sync_next(struct mail_ind
 						   &sync_list[i]);
 	}
 	sync_list[i].idx++;
-	return 1;
+	return TRUE;
 }
 
 bool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx)
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-index/mail-index.h
--- a/src/lib-index/mail-index.h	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-index/mail-index.h	Sun Aug 12 18:07:22 2007 +0300
@@ -258,8 +258,8 @@ int mail_index_sync_begin(struct mail_in
 			  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. */
-int mail_index_sync_next(struct mail_index_sync_ctx *ctx,
-			 struct mail_index_sync_rec *sync_rec);
+bool mail_index_sync_next(struct mail_index_sync_ctx *ctx,
+			  struct mail_index_sync_rec *sync_rec);
 /* Returns TRUE if there's more to sync. */
 bool mail_index_sync_have_more(struct mail_index_sync_ctx *ctx);
 /* Reset syncing to initial state after mail_index_sync_begin(), so you can
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-index/mailbox-list-index-sync.c
--- a/src/lib-index/mailbox-list-index-sync.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-index/mailbox-list-index-sync.c	Sun Aug 12 18:07:22 2007 +0300
@@ -371,7 +371,7 @@ static int sync_mail_sync_init(struct ma
 
 	/* we should have only external transactions in here, for which we
 	   don't need to do anything but write them to the index */
-	while (mail_index_sync_next(ctx->mail_sync_ctx, &sync_rec) > 0)
+	while (mail_index_sync_next(ctx->mail_sync_ctx, &sync_rec))
 		;
 	return 0;
 }
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/index/cydir/cydir-sync.c
--- a/src/lib-storage/index/cydir/cydir-sync.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-sync.c	Sun Aug 12 18:07:22 2007 +0300
@@ -59,13 +59,12 @@ cydir_sync_expunge(struct cydir_sync_con
 	}
 }
 
-static int cydir_sync_index(struct cydir_sync_context *ctx)
+static void cydir_sync_index(struct cydir_sync_context *ctx)
 {
 	struct mailbox *box = &ctx->mbox->ibox.box;
 	const struct mail_index_header *hdr;
 	struct mail_index_sync_rec sync_rec;
 	uint32_t seq1, seq2;
-	int ret = 1;
 
 	hdr = mail_index_get_header(ctx->sync_view);
 	if (hdr->uid_validity != 0)
@@ -81,9 +80,7 @@ static int cydir_sync_index(struct cydir
 					     seq1, seq2);
 	}
 
-	while (ret > 0 &&
-	       (ret = mail_index_sync_next(ctx->index_sync_ctx,
-					   &sync_rec)) > 0) {
+	while (mail_index_sync_next(ctx->index_sync_ctx, &sync_rec)) {
 		mail_index_lookup_uid_range(ctx->sync_view,
 					    sync_rec.uid1, sync_rec.uid2,
 					    &seq1, &seq2);
@@ -110,7 +107,6 @@ static int cydir_sync_index(struct cydir
 
 	if (box->v.sync_notify != NULL)
 		box->v.sync_notify(box, 0, 0);
-	return ret;
 }
 
 int cydir_sync_begin(struct cydir_mailbox *mbox,
@@ -137,12 +133,7 @@ int cydir_sync_begin(struct cydir_mailbo
 		return ret;
 	}
 
-	if (cydir_sync_index(ctx) < 0) {
-		mail_index_sync_rollback(&ctx->index_sync_ctx);
-		i_free(ctx);
-		return -1;
-	}
-
+	cydir_sync_index(ctx);
 	*ctx_r = ctx;
 	return 0;
 }
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/index/dbox/dbox-sync.c
--- a/src/lib-storage/index/dbox/dbox-sync.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/index/dbox/dbox-sync.c	Sun Aug 12 18:07:22 2007 +0300
@@ -420,12 +420,8 @@ static int dbox_sync_index(struct dbox_s
 	ctx->syncs = hash_create(default_pool, ctx->pool, 0, NULL, NULL);
 	i_array_init(&ctx->added_file_seqs, 64);
 	for (;;) {
-		ret = mail_index_sync_next(ctx->index_sync_ctx, &sync_rec);
-		if (ret <= 0) {
-			if (ret < 0)
-				mail_storage_set_index_error(&ctx->mbox->ibox);
-			break;
-		}
+		if (!mail_index_sync_next(ctx->index_sync_ctx, &sync_rec))
+			break;
 		if (dbox_sync_add(ctx, &sync_rec) < 0) {
 			ret = -1;
 			break;
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/index/index-sync-changes.c
--- a/src/lib-storage/index/index-sync-changes.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/index/index-sync-changes.c	Sun Aug 12 18:07:22 2007 +0300
@@ -86,13 +86,12 @@ index_sync_changes_have_expunges(struct 
 	return FALSE;
 }
 
-int index_sync_changes_read(struct index_sync_changes_context *ctx,
-			    uint32_t uid, bool *sync_expunge_r)
+void index_sync_changes_read(struct index_sync_changes_context *ctx,
+			     uint32_t uid, bool *sync_expunge_r)
 {
 	struct mail_index_sync_rec *sync_rec = &ctx->sync_rec;
 	uint32_t seq1, seq2;
 	unsigned int orig_count;
-	int ret;
 
 	*sync_expunge_r = FALSE;
 
@@ -108,13 +107,7 @@ int index_sync_changes_read(struct index
 				*sync_expunge_r = TRUE;
 		}
 
-		ret = mail_index_sync_next(ctx->index_sync_ctx, sync_rec);
-		if (ret < 0) {
-			mail_storage_set_index_error(ctx->ibox);
-			return -1;
-		}
-
-		if (ret == 0) {
+		if (!mail_index_sync_next(ctx->index_sync_ctx, sync_rec)) {
 			memset(sync_rec, 0, sizeof(*sync_rec));
 			break;
 		}
@@ -154,8 +147,6 @@ int index_sync_changes_read(struct index
 		*sync_expunge_r =
 			index_sync_changes_have_expunges(ctx, orig_count);
 	}
-
-	return 0;
 }
 
 bool index_sync_changes_have(struct index_sync_changes_context *ctx)
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/index/index-sync-changes.h
--- a/src/lib-storage/index/index-sync-changes.h	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/index/index-sync-changes.h	Sun Aug 12 18:07:22 2007 +0300
@@ -13,8 +13,8 @@ void index_sync_changes_delete_to(struct
 void index_sync_changes_delete_to(struct index_sync_changes_context *ctx,
 				  uint32_t last_uid);
 
-int index_sync_changes_read(struct index_sync_changes_context *ctx,
-			    uint32_t uid, bool *sync_expunge_r);
+void index_sync_changes_read(struct index_sync_changes_context *ctx,
+			     uint32_t uid, bool *sync_expunge_r);
 bool index_sync_changes_have(struct index_sync_changes_context *ctx);
 uint32_t
 index_sync_changes_get_next_uid(struct index_sync_changes_context *ctx);
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/index/maildir/maildir-sync-index.c
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Sun Aug 12 18:07:22 2007 +0300
@@ -362,12 +362,7 @@ int maildir_sync_index(struct maildir_in
 			continue;
 		}
 
-		if (index_sync_changes_read(ctx->sync_changes, rec->uid,
-					    &expunged) < 0) {
-			ret = -1;
-			break;
-		}
-
+		index_sync_changes_read(ctx->sync_changes, rec->uid, &expunged);
 		if (expunged) {
 			if (maildir_file_do(mbox, ctx->uid,
 					    maildir_expunge, ctx) >= 0) {
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/index/mbox/mbox-sync.c
--- a/src/lib-storage/index/mbox/mbox-sync.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Sun Aug 12 18:07:22 2007 +0300
@@ -163,23 +163,19 @@ mbox_sync_read_next_mail(struct mbox_syn
 	return 1;
 }
 
-static int mbox_sync_read_index_syncs(struct mbox_sync_context *sync_ctx,
-				      uint32_t uid, bool *sync_expunge_r)
+static void mbox_sync_read_index_syncs(struct mbox_sync_context *sync_ctx,
+				       uint32_t uid, bool *sync_expunge_r)
 {
 	if (uid == 0 || sync_ctx->index_reset) {
 		/* nothing for this or the future ones */
 		uid = (uint32_t)-1;
 	}
 
-	if (index_sync_changes_read(sync_ctx->sync_changes, uid,
-				    sync_expunge_r) < 0)
-		return -1;
-
+	index_sync_changes_read(sync_ctx->sync_changes, uid, sync_expunge_r);
 	if (sync_ctx->mbox->mbox_readonly) {
 		/* we can't expunge anything from read-only mboxes */
 		*sync_expunge_r = FALSE;
 	}
-	return 0;
 }
 
 static bool
@@ -1017,10 +1013,9 @@ static int mbox_sync_loop(struct mbox_sy
 		/* get all sync records related to this message. with pseudo
 		   message just get the first sync record so we can jump to
 		   it with partial seeking. */
-		if (mbox_sync_read_index_syncs(sync_ctx,
-					       mail_ctx->mail.pseudo ? 1 : uid,
-					       &expunged) < 0)
-			return -1;
+		mbox_sync_read_index_syncs(sync_ctx,
+					   mail_ctx->mail.pseudo ? 1 : uid,
+					   &expunged);
 
 		if (mail_ctx->mail.pseudo) {
 			/* if it was set, it was for the next message */
@@ -1690,8 +1685,7 @@ __again:
 		bool expunged;
 		uint32_t uid;
 
-		if (mbox_sync_read_index_syncs(&sync_ctx, 1, &expunged) < 0)
-			return -1;
+		mbox_sync_read_index_syncs(&sync_ctx, 1, &expunged);
 		uid = expunged ? 1 :
 			index_sync_changes_get_next_uid(sync_ctx.sync_changes);
 		if (uid == 0) {
diff -r 5f66277bbe40 -r ce83635191d4 src/lib-storage/list/index-mailbox-list-sync.c
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Sun Aug 12 18:02:29 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Sun Aug 12 18:07:22 2007 +0300
@@ -75,7 +75,7 @@ static int index_list_update_mail_index(
 
 	/* we should have only external transactions in here, for which we
 	   don't need to do anything but write them to the index */
-	while (mail_index_sync_next(mail_sync_ctx, &sync_rec) > 0)
+	while (mail_index_sync_next(mail_sync_ctx, &sync_rec))
 		;
 
 	return mail_index_sync_commit(&mail_sync_ctx);


More information about the dovecot-cvs mailing list