Mercurial > dovecot > core-2.2
changeset 22313:d4f4499c2a3a
lib-storage: mailbox_sync_init() - open mailbox immediately if it's not open yet
This simplifies the work for plugins that want to hook into
mailbox.sync_init() so they no longer have to handle the "mailbox isn't
opened" case.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Mon, 10 Jul 2017 14:19:47 +0300 |
parents | 19f52d0ede61 |
children | 76a93ccad769 |
files | src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c |
diffstat | 2 files changed, 19 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-storage-private.h Mon Jul 10 13:56:49 2017 +0300 +++ b/src/lib-storage/mail-storage-private.h Mon Jul 10 14:19:47 2017 +0300 @@ -699,6 +699,7 @@ struct mailbox_sync_context { struct mailbox *box; enum mailbox_sync_flags flags; + bool open_failed; }; struct mailbox_header_lookup_ctx {
--- a/src/lib-storage/mail-storage.c Mon Jul 10 13:56:49 2017 +0300 +++ b/src/lib-storage/mail-storage.c Mon Jul 10 14:19:47 2017 +0300 @@ -1863,6 +1863,15 @@ i_panic("Trying to sync mailbox %s with open transactions", box->name); } + if (!box->opened) { + if (mailbox_open(box) < 0) { + ctx = i_new(struct mailbox_sync_context, 1); + ctx->box = box; + ctx->flags = flags; + ctx->open_failed = TRUE; + return ctx; + } + } T_BEGIN { ctx = box->v.sync_init(box, flags); } T_END; @@ -1872,6 +1881,8 @@ bool mailbox_sync_next(struct mailbox_sync_context *ctx, struct mailbox_sync_rec *sync_rec_r) { + if (ctx->open_failed) + return FALSE; return ctx->box->v.sync_next(ctx, sync_rec_r); } @@ -1887,7 +1898,13 @@ *_ctx = NULL; i_zero(status_r); - ret = box->v.sync_deinit(ctx, status_r); + + if (!ctx->open_failed) + ret = box->v.sync_deinit(ctx, status_r); + else { + i_free(ctx); + ret = -1; + } if (ret < 0 && box->inbox_user && !box->storage->user->inbox_open_error_logged) { errormsg = mailbox_get_last_internal_error(box, &error);