dovecot-2.0: doveadm: Don't fail immediately if some mailbox can...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jun 9 21:47:28 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/e3d2d9427d3d
changeset: 11515:e3d2d9427d3d
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jun 09 19:47:25 2010 +0100
description:
doveadm: Don't fail immediately if some mailbox can't be opened.

diffstat:

 src/doveadm/doveadm-mail-mailbox-status.c |   6 ++-
 src/doveadm/doveadm-mail.c                |  40 ++++++++++++-------
 src/doveadm/doveadm-mail.h                |   6 ++-
 3 files changed, 34 insertions(+), 18 deletions(-)

diffs (130 lines):

diff -r 9c4b07e13cd2 -r e3d2d9427d3d src/doveadm/doveadm-mail-mailbox-status.c
--- a/src/doveadm/doveadm-mail-mailbox-status.c	Wed Jun 09 19:42:09 2010 +0100
+++ b/src/doveadm/doveadm-mail-mailbox-status.c	Wed Jun 09 19:47:25 2010 +0100
@@ -109,7 +109,11 @@
 	struct mailbox_status status;
 	uint8_t mailbox_guid[MAIL_GUID_128_SIZE];
 
-	box = doveadm_mailbox_find_and_sync(ctx->ctx.cur_mail_user, info->name);
+	if (doveadm_mailbox_find_and_sync(ctx->ctx.cur_mail_user,
+					  info->name, &box) < 0) {
+		ctx->ctx.failed = TRUE;
+		return;
+	}
 	mailbox_get_status(box, ctx->items, &status);
 	if (ctx->guid) {
 		if (mailbox_get_guid(box, mailbox_guid) < 0)
diff -r 9c4b07e13cd2 -r e3d2d9427d3d src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Wed Jun 09 19:42:09 2010 +0100
+++ b/src/doveadm/doveadm-mail.c	Wed Jun 09 19:47:25 2010 +0100
@@ -71,8 +71,8 @@
 	return ctx;
 }
 
-static struct mailbox *
-mailbox_find_and_open(struct mail_user *user, const char *mailbox)
+static int mailbox_find_and_open(struct mail_user *user, const char *mailbox,
+				 struct mailbox **box_r)
 {
 	struct mail_namespace *ns;
 	struct mailbox *box;
@@ -91,25 +91,28 @@
 	box = mailbox_alloc(ns->list, mailbox, MAILBOX_FLAG_KEEP_RECENT |
 			    MAILBOX_FLAG_IGNORE_ACLS);
 	if (mailbox_open(box) < 0) {
-		i_fatal("Opening mailbox %s failed: %s", orig_mailbox,
+		i_error("Opening mailbox %s failed: %s", orig_mailbox,
 			mail_storage_get_last_error(mailbox_get_storage(box),
 						    NULL));
+		mailbox_free(&box);
+		return -1;
 	}
-	return box;
+	*box_r = box;
+	return 0;
 }
 
-struct mailbox *
-doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox)
+int doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
+				  struct mailbox **box_r)
 {
-	struct mailbox *box;
-
-	box = mailbox_find_and_open(user, mailbox);
-	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
-		i_fatal("Syncing mailbox %s failed: %s", mailbox,
-			mail_storage_get_last_error(mailbox_get_storage(box),
+	if (mailbox_find_and_open(user, mailbox, box_r) < 0)
+		return -1;
+	if (mailbox_sync(*box_r, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
+		i_error("Syncing mailbox %s failed: %s", mailbox,
+			mail_storage_get_last_error(mailbox_get_storage(*box_r),
 						    NULL));
+		return -1;
 	}
-	return box;
+	return 0;
 }
 
 struct mail_search_args *
@@ -140,13 +143,17 @@
 	struct mail_storage *storage;
 	struct mailbox *box;
 
-	box = mailbox_find_and_open(user, ctx->mailbox);
+	if (mailbox_find_and_open(user, ctx->mailbox, &box) < 0) {
+		_ctx->failed = TRUE;
+		return;
+	}
 	storage = mailbox_get_storage(box);
 	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FORCE_RESYNC |
 			 MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) < 0) {
-		i_fatal("Forcing a resync on mailbox %s failed: %s",
+		i_error("Forcing a resync on mailbox %s failed: %s",
 			ctx->mailbox,
 			mail_storage_get_last_error(storage, NULL));
+		_ctx->failed = TRUE;
 	}
 	mailbox_free(&box);
 }
@@ -384,6 +391,9 @@
 		doveadm_mail_all_users(ctx, wildcard_user, service_flags);
 	}
 	ctx->v.deinit(ctx);
+
+	if (ctx->failed)
+		exit(FATAL_DEFAULT);
 }
 
 void dm_printf(struct doveadm_mail_cmd_context *ctx, const char *format, ...)
diff -r 9c4b07e13cd2 -r e3d2d9427d3d src/doveadm/doveadm-mail.h
--- a/src/doveadm/doveadm-mail.h	Wed Jun 09 19:42:09 2010 +0100
+++ b/src/doveadm/doveadm-mail.h	Wed Jun 09 19:47:25 2010 +0100
@@ -5,6 +5,7 @@
 #include "doveadm.h"
 #include "module-context.h"
 
+struct mailbox;
 struct mail_user;
 struct mail_storage_service_ctx;
 struct mail_storage_service_input;
@@ -45,6 +46,7 @@
 
 	unsigned int iterate_all_users:1;
 	unsigned int dm_printf_last_lf:1;
+	unsigned int failed:1;
 };
 
 struct doveadm_mail_cmd {
@@ -70,8 +72,8 @@
 void doveadm_mail_init(void);
 void doveadm_mail_deinit(void);
 
-struct mailbox *
-doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox);
+int doveadm_mailbox_find_and_sync(struct mail_user *user, const char *mailbox,
+				  struct mailbox **box_r);
 struct mail_search_args *
 doveadm_mail_build_search_args(const char *const args[]);
 const char *const *doveadm_mailbox_args_to_mutf7(const char *const args[]);


More information about the dovecot-cvs mailing list