]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm: Don't fail immediately if some mailbox can't be opened.
authorTimo Sirainen <tss@iki.fi>
Wed, 9 Jun 2010 18:47:25 +0000 (19:47 +0100)
committerTimo Sirainen <tss@iki.fi>
Wed, 9 Jun 2010 18:47:25 +0000 (19:47 +0100)
--HG--
branch : HEAD

src/doveadm/doveadm-mail-mailbox-status.c
src/doveadm/doveadm-mail.c
src/doveadm/doveadm-mail.h

index 1ea3381885d4d04507c2c65036f10a7a6d5d82a1..c1d8846b48ace1427526f5ebb9f94c8792bf5edd 100644 (file)
@@ -109,7 +109,11 @@ status_mailbox(struct status_cmd_context *ctx, const struct mailbox_info *info)
        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)
index 1adea3dfaff8fc0db3707a33d16ed17bf288412f..7120ebcc8966378943a4624508dab146390c69d4 100644 (file)
@@ -71,8 +71,8 @@ static struct doveadm_mail_cmd_context *cmd_purge_alloc(void)
        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 @@ mailbox_find_and_open(struct mail_user *user, const char *mailbox)
        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 @@ static void cmd_force_resync_run(struct doveadm_mail_cmd_context *_ctx,
        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_cmd(const struct doveadm_mail_cmd *cmd, int argc, char *argv[])
                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, ...)
index 4c7b2c8da999f3ccd223e3ad895661faf0de95b2..e1e105ffa3bd87277ccb76f8f2658e553035ec40 100644 (file)
@@ -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 @@ struct doveadm_mail_cmd_context {
 
        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 @@ bool doveadm_mail_has_subcommands(const char *cmd_name);
 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[]);