dovecot-2.0: lib-storage: Changed mailbox_sync() and mailbox_syn...

dovecot at dovecot.org dovecot at dovecot.org
Thu Dec 17 02:28:03 EET 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/50364f04cf13
changeset: 10509:50364f04cf13
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Dec 16 19:27:57 2009 -0500
description:
lib-storage: Changed mailbox_sync() and mailbox_sync_deinit() APIs.
Although we're already in beta stage, this is simple enough of a change that
it shouldn't matter much. Having syncing also return status information made
the API ugly and the status information wasn't even wanted all that often.

diffstat:

25 files changed, 82 insertions(+), 91 deletions(-)
src/doveadm/doveadm-mail.c                     |    2 -
src/dsync/dsync-worker-local.c                 |    7 ++----
src/imap/cmd-close.c                           |    2 -
src/imap/cmd-select.c                          |   10 ++++----
src/imap/imap-status.c                         |    7 ++++--
src/imap/imap-sync.c                           |   21 +++++++++++-------
src/lda/main.c                                 |    2 -
src/lib-lda/mail-deliver.c                     |    5 +---
src/lib-storage/index/index-storage.h          |    3 --
src/lib-storage/index/index-sync.c             |    7 +-----
src/lib-storage/list/index-mailbox-list-sync.c |   28 ++++++++----------------
src/lib-storage/mail-storage-private.h         |    3 --
src/lib-storage/mail-storage.c                 |   18 +++++++--------
src/lib-storage/mail-storage.h                 |   13 +++++------
src/lib-storage/test-mailbox.c                 |    8 +++---
src/lmtp/commands.c                            |    3 --
src/plugins/expire/expire-tool.c               |    2 -
src/plugins/lazy-expunge/lazy-expunge-plugin.c |    2 -
src/plugins/mbox-snarf/mbox-snarf-plugin.c     |    4 +--
src/plugins/quota/quota-count.c                |    2 -
src/plugins/quota/quota-storage.c              |    7 ++----
src/plugins/trash/trash-plugin.c               |    2 -
src/plugins/virtual/virtual-sync.c             |    7 +++---
src/pop3/pop3-client.c                         |    5 ++--
src/pop3/pop3-commands.c                       |    3 --

diffs (truncated from 590 to 300 lines):

diff -r c17386a4e594 -r 50364f04cf13 src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/doveadm/doveadm-mail.c	Wed Dec 16 19:27:57 2009 -0500
@@ -68,7 +68,7 @@ static void cmd_force_resync(struct mail
 	box = mailbox_find_and_open(user, mailbox);
 	storage = mailbox_get_storage(box);
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
-			 MAILBOX_SYNC_FLAG_FIX_INCONSISTENT, 0, NULL) < 0) {
+			 MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) < 0) {
 		i_fatal("Forcing a resync on mailbox %s failed: %s", mailbox,
 			mail_storage_get_last_error(storage, NULL));
 	}
diff -r c17386a4e594 -r 50364f04cf13 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/dsync/dsync-worker-local.c	Wed Dec 16 19:27:57 2009 -0500
@@ -459,7 +459,7 @@ local_worker_mailbox_iter_next(struct ds
 	}
 
 	box = mailbox_alloc(info->ns->list, storage_name, NULL, flags);
-	if (mailbox_sync(box, 0, 0, NULL) < 0) {
+	if (mailbox_sync(box, 0) < 0) {
 		struct mail_storage *storage = mailbox_get_storage(box);
 
 		i_error("Failed to sync mailbox %s: %s", info->name,
@@ -653,7 +653,7 @@ static int local_mailbox_open(struct loc
 	}
 
 	box = mailbox_alloc(lbox->ns->list, lbox->storage_name, NULL, flags);
-	if (mailbox_sync(box, 0, 0, NULL) < 0) {
+	if (mailbox_sync(box, 0) < 0) {
 		struct mail_storage *storage = mailbox_get_storage(box);
 
 		i_error("Failed to sync mailbox %s: %s", lbox->storage_name,
@@ -1148,8 +1148,7 @@ static void local_worker_mailbox_close(s
 	array_clear(&worker->saved_uids);
 
 	if (mailbox_transaction_commit(&trans) < 0 ||
-	    mailbox_sync(worker->selected_box,
-			 MAILBOX_SYNC_FLAG_FULL_WRITE, 0, NULL) < 0)
+	    mailbox_sync(worker->selected_box, MAILBOX_SYNC_FLAG_FULL_WRITE) < 0)
 		dsync_worker_set_failure(&worker->worker);
 
 	mailbox_close(&worker->selected_box);
diff -r c17386a4e594 -r 50364f04cf13 src/imap/cmd-close.c
--- a/src/imap/cmd-close.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/imap/cmd-close.c	Wed Dec 16 19:27:57 2009 -0500
@@ -20,7 +20,7 @@ bool cmd_close(struct client_command_con
 	storage = mailbox_get_storage(mailbox);
 	if ((ret = imap_expunge(mailbox, NULL)) < 0)
 		client_send_untagged_storage_error(client, storage);
-	if (mailbox_sync(mailbox, 0, 0, NULL) < 0)
+	if (mailbox_sync(mailbox, 0) < 0)
 		client_send_untagged_storage_error(client, storage);
 
 	mailbox_close(&mailbox);
diff -r c17386a4e594 -r 50364f04cf13 src/imap/cmd-select.c
--- a/src/imap/cmd-select.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/imap/cmd-select.c	Wed Dec 16 19:27:57 2009 -0500
@@ -277,15 +277,15 @@ select_open(struct imap_select_context *
 
 	if (client->enabled_features != 0)
 		mailbox_enable(ctx->box, client->enabled_features);
-	if (mailbox_sync(ctx->box, MAILBOX_SYNC_FLAG_FULL_READ,
-			 STATUS_MESSAGES | STATUS_RECENT |
-			 STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
-			 STATUS_UIDNEXT | STATUS_KEYWORDS |
-			 STATUS_HIGHESTMODSEQ, &status) < 0) {
+	if (mailbox_sync(ctx->box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		client_send_storage_error(ctx->cmd,
 					  mailbox_get_storage(ctx->box));
 		return -1;
 	}
+	mailbox_get_status(ctx->box, STATUS_MESSAGES | STATUS_RECENT |
+			   STATUS_FIRST_UNSEEN_SEQ | STATUS_UIDVALIDITY |
+			   STATUS_UIDNEXT | STATUS_KEYWORDS |
+			   STATUS_HIGHESTMODSEQ, &status);
 
 	client->mailbox = ctx->box;
 	client->select_counter++;
diff -r c17386a4e594 -r 50364f04cf13 src/imap/imap-status.c
--- a/src/imap/imap-status.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/imap/imap-status.c	Wed Dec 16 19:27:57 2009 -0500
@@ -75,9 +75,12 @@ int imap_status_get(struct client_comman
 	if (client->enabled_features != 0)
 		mailbox_enable(box, client->enabled_features);
 
-	ret = mailbox_sync(box, 0, items, status_r);
-	if (ret < 0) {
+	ret = mailbox_sync(box, 0);
+	if (ret == 0)
+		mailbox_get_status(box, items, status_r);
+	else {
 		struct mail_storage *storage = mailbox_get_storage(box);
+
 		*error_r = mail_storage_get_last_error(storage, &error);
 		*error_r = imap_get_error_string(cmd, *error_r, error);
 	}
diff -r c17386a4e594 -r 50364f04cf13 src/imap/imap-sync.c
--- a/src/imap/imap-sync.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/imap/imap-sync.c	Wed Dec 16 19:27:57 2009 -0500
@@ -162,18 +162,19 @@ static void
 static void
 imap_sync_send_highestmodseq(struct imap_sync_context *ctx,
 			     const struct mailbox_status *status,
+			     const struct mailbox_sync_status *sync_status,
 			     struct client_command_context *sync_cmd)
 {
 	struct client *client = ctx->client;
 	uint64_t send_modseq = 0;
 
-	if (status->sync_delayed_expunges &&
+	if (sync_status->sync_delayed_expunges &&
 	    client->highest_fetch_modseq > client->sync_last_full_modseq) {
 		/* if client updates highest-modseq using returned MODSEQs
 		   it loses expunges. try to avoid this by sending it a lower
 		   pre-expunge HIGHESTMODSEQ reply. */
 		send_modseq = client->sync_last_full_modseq;
-	} else if (!status->sync_delayed_expunges &&
+	} else if (!sync_status->sync_delayed_expunges &&
 		   status->highest_modseq > client->sync_last_full_modseq &&
 		   status->highest_modseq > client->highest_fetch_modseq) {
 		/* we've probably sent some VANISHED or EXISTS replies which
@@ -199,7 +200,7 @@ imap_sync_send_highestmodseq(struct imap
 			(unsigned long long)send_modseq));
 	}
 
-	if (!status->sync_delayed_expunges) {
+	if (!sync_status->sync_delayed_expunges) {
 		/* no delayed expunges, remember this for future */
 		client->sync_last_full_modseq = status->highest_modseq;
 	}
@@ -211,21 +212,23 @@ int imap_sync_deinit(struct imap_sync_co
 {
 	struct client *client = ctx->client;
 	struct mailbox_status status;
+	struct mailbox_sync_status sync_status;
 	int ret;
 
 	mail_free(&ctx->mail);
 	if (array_is_created(&ctx->expunges))
 		array_free(&ctx->expunges);
 
-	if (mailbox_sync_deinit(&ctx->sync_ctx, STATUS_UIDVALIDITY |
-				STATUS_MESSAGES | STATUS_RECENT |
-				STATUS_HIGHESTMODSEQ, &status) < 0 ||
+	if (mailbox_sync_deinit(&ctx->sync_ctx, &sync_status) < 0 ||
 	    ctx->failed) {
 		mailbox_transaction_rollback(&ctx->t);
 		array_free(&ctx->tmp_keywords);
 		i_free(ctx);
 		return -1;
 	}
+	mailbox_get_status(ctx->box, STATUS_UIDVALIDITY |
+			   STATUS_MESSAGES | STATUS_RECENT |
+			   STATUS_HIGHESTMODSEQ, &status);
 
 	ret = mailbox_transaction_commit(&ctx->t);
 
@@ -253,8 +256,10 @@ int imap_sync_deinit(struct imap_sync_co
 	   now it contains added/removed messages. */
 	imap_sync_send_search_updates(ctx);
 
-	if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0)
-		imap_sync_send_highestmodseq(ctx, &status, sync_cmd);
+	if ((client->enabled_features & MAILBOX_FEATURE_QRESYNC) != 0) {
+		imap_sync_send_highestmodseq(ctx, &status, &sync_status,
+					     sync_cmd);
+	}
 
 	if (array_is_created(&ctx->search_removes)) {
 		array_free(&ctx->search_removes);
diff -r c17386a4e594 -r 50364f04cf13 src/lda/main.c
--- a/src/lda/main.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/lda/main.c	Wed Dec 16 19:27:57 2009 -0500
@@ -416,7 +416,7 @@ int main(int argc, char *argv[])
 		i_fatal("Can't open delivery mail as raw: %s",
 			mail_storage_get_last_error(box->storage, &error));
 	}
-	if (mailbox_sync(box, 0, 0, NULL) < 0) {
+	if (mailbox_sync(box, 0) < 0) {
 		i_fatal("Can't sync delivery mail: %s",
 			mail_storage_get_last_error(box->storage, &error));
 	}
diff -r c17386a4e594 -r 50364f04cf13 src/lib-lda/mail-deliver.c
--- a/src/lib-lda/mail-deliver.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/lib-lda/mail-deliver.c	Wed Dec 16 19:27:57 2009 -0500
@@ -129,8 +129,7 @@ mailbox_open_or_create_synced(struct mai
 	}
 
 	/* and try opening again */
-	if (mailbox_open(box) < 0 ||
-	    mailbox_sync(box, 0, 0, NULL) < 0) {
+	if (mailbox_sync(box, 0) < 0) {
 		*error_r = mail_storage_get_last_error(storage, &error);
 		mailbox_close(&box);
 		return NULL;
@@ -212,7 +211,7 @@ int mail_deliver_save(struct mail_delive
 		ctx->saved_mail = TRUE;
 		mail_deliver_log(ctx, "saved mail to %s", mailbox_name);
 
-		if (ctx->save_dest_mail && mailbox_sync(box, 0, 0, NULL) == 0) {
+		if (ctx->save_dest_mail && mailbox_sync(box, 0) == 0) {
 			range = array_idx(&changes.saved_uids, 0);
 			i_assert(range[0].seq1 == range[0].seq2);
 
diff -r c17386a4e594 -r 50364f04cf13 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/lib-storage/index/index-storage.h	Wed Dec 16 19:27:57 2009 -0500
@@ -122,8 +122,7 @@ bool index_mailbox_sync_next(struct mail
 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);
+			      struct mailbox_sync_status *status_r);
 
 int index_storage_sync(struct mailbox *box, enum mailbox_sync_flags flags);
 enum mailbox_sync_type index_sync_type_convert(enum mail_index_sync_type type);
diff -r c17386a4e594 -r 50364f04cf13 src/lib-storage/index/index-sync.c
--- a/src/lib-storage/index/index-sync.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/lib-storage/index/index-sync.c	Wed Dec 16 19:27:57 2009 -0500
@@ -298,8 +298,7 @@ index_mailbox_expunge_unseen_recent(stru
 }
 
 int index_mailbox_sync_deinit(struct mailbox_sync_context *_ctx,
-			      enum mailbox_status_items status_items,
-			      struct mailbox_status *status_r)
+			      struct mailbox_sync_status *status_r)
 {
 	struct index_mailbox_sync_context *ctx =
 		(struct index_mailbox_sync_context *)_ctx;
@@ -342,10 +341,8 @@ int index_mailbox_sync_deinit(struct mai
 		}
 	}
 
-	if (ret == 0 && status_items != 0) {
-		mailbox_get_status(_ctx->box, status_items, status_r);
+	if (status_r != NULL)
 		status_r->sync_delayed_expunges = delayed_expunges;
-	}
 
 	index_sync_search_results_update(ctx);
 
diff -r c17386a4e594 -r 50364f04cf13 src/lib-storage/list/index-mailbox-list-sync.c
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Wed Dec 16 18:18:02 2009 -0500
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Wed Dec 16 19:27:57 2009 -0500
@@ -306,22 +306,18 @@ static bool index_list_sync_next(struct 
 }
 
 static int index_list_sync_deinit(struct mailbox_sync_context *ctx,
-				  enum mailbox_status_items status_items,
-				  struct mailbox_status *status_r)
+				  struct mailbox_sync_status *status_r)
 {
 	struct mailbox *box = ctx->box;
 	struct index_list_mailbox *ibox = INDEX_LIST_STORAGE_CONTEXT(box);
 	struct index_mailbox_list *ilist;
 	struct mail_index_view *view;
-	struct mailbox_status tmp_status, *status;
+	struct mailbox_status status;
 	uint32_t uid, seq;
 
 	if (!box->opened) {
 		/* nothing synced. just return the status. */
 		i_free(ctx);
-
-		if (status_items != 0)
-			index_list_get_status(box, status_items, status_r);
 		return 0;
 	}
 
@@ -329,16 +325,10 @@ static int index_list_sync_deinit(struct
 
 	if (ilist == NULL) {
 		/* indexing disabled */
-		return ibox->module_ctx.super.
-			sync_deinit(ctx, status_items, status_r);
-	}
-
-	/* if status_items == 0, the status_r may be NULL. we really want to
-	   know the status anyway, so save it elsewhere then */
-	status = status_items == 0 ? &tmp_status : status_r;
-	status_items |= CACHED_STATUS_ITEMS;
-
-	if (ibox->module_ctx.super.sync_deinit(ctx, status_items, status) < 0)
+		return ibox->module_ctx.super.sync_deinit(ctx, status_r);
+	}
+
+	if (ibox->module_ctx.super.sync_deinit(ctx, status_r) < 0)
 		return -1;
 	ctx = NULL;
 
@@ -349,8 +339,10 @@ static int index_list_sync_deinit(struct
 	}
 
 	view = mail_index_view_open(ilist->mail_index);
-	if (mail_index_lookup_seq(view, uid, &seq))
-		(void)index_list_update(ilist, box, view, seq, status);
+	if (mail_index_lookup_seq(view, uid, &seq)) {
+		mailbox_get_status(box, CACHED_STATUS_ITEMS, &status);


More information about the dovecot-cvs mailing list