dovecot-1.1: quota: Fixed error handling if quota shrinking fail...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Aug 12 22:23:29 EEST 2008
details: http://hg.dovecot.org/dovecot-1.1/rev/f267eb97c598
changeset: 7817:f267eb97c598
user: Timo Sirainen <tss at iki.fi>
date: Tue Aug 12 15:23:21 2008 -0400
description:
quota: Fixed error handling if quota shrinking fails when deleting a mailbox.
diffstat:
1 file changed, 51 insertions(+), 34 deletions(-)
src/plugins/quota/quota-storage.c | 85 ++++++++++++++++++++++---------------
diffs (109 lines):
diff -r a2d54b89cf21 -r f267eb97c598 src/plugins/quota/quota-storage.c
--- a/src/plugins/quota/quota-storage.c Fri Aug 08 16:45:21 2008 -0400
+++ b/src/plugins/quota/quota-storage.c Tue Aug 12 15:23:21 2008 -0400
@@ -385,16 +385,45 @@ quota_mailbox_open(struct mail_storage *
}
static int
-quota_mailbox_list_delete(struct mailbox_list *list, const char *name)
-{
- struct quota_mailbox_list *qlist = QUOTA_LIST_CONTEXT(list);
- struct mailbox *box;
+quota_mailbox_delete_shrink_quota(struct mailbox *box)
+{
struct mail_search_context *ctx;
struct mailbox_transaction_context *t;
struct quota_transaction_context *qt;
struct mail *mail;
struct mail_search_arg search_arg;
+ int ret;
+
+ if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0)
+ return -1;
+
+ memset(&search_arg, 0, sizeof(search_arg));
+ search_arg.type = SEARCH_ALL;
+
+ t = mailbox_transaction_begin(box, 0);
+ qt = QUOTA_CONTEXT(t);
+ ctx = mailbox_search_init(t, NULL, &search_arg, NULL);
+
+ mail = mail_alloc(t, 0, NULL);
+ while (mailbox_search_next(ctx, mail) > 0)
+ quota_free(qt, mail);
+ mail_free(&mail);
+
+ ret = mailbox_search_deinit(&ctx);
+ if (ret < 0)
+ mailbox_transaction_rollback(&t);
+ else
+ ret = mailbox_transaction_commit(&t);
+ return ret;
+}
+
+static int
+quota_mailbox_list_delete(struct mailbox_list *list, const char *name)
+{
+ struct quota_mailbox_list *qlist = QUOTA_LIST_CONTEXT(list);
+ struct mailbox *box;
enum mail_error error;
+ const char *str;
int ret;
/* This is a bit annoying to handle. We'll have to open the mailbox
@@ -404,37 +433,25 @@ quota_mailbox_list_delete(struct mailbox
box = mailbox_open(qlist->storage, name, NULL, MAILBOX_OPEN_FAST |
MAILBOX_OPEN_KEEP_RECENT | MAILBOX_OPEN_KEEP_LOCKED);
if (box == NULL) {
- (void)mail_storage_get_last_error(qlist->storage, &error);
- if (error != MAIL_ERROR_NOTPOSSIBLE)
- return -1;
-
- /* mailbox isn't selectable */
- return qlist->module_ctx.super.delete_mailbox(list, name);
- }
-
- if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0) {
+ str = mail_storage_get_last_error(qlist->storage, &error);
+ if (error != MAIL_ERROR_NOTPOSSIBLE) {
+ ret = -1;
+ } else {
+ /* mailbox isn't selectable */
+ ret = 0;
+ }
+ } else {
+ ret = quota_mailbox_delete_shrink_quota(box);
+ }
+ if (ret < 0) {
+ str = mail_storage_get_last_error(qlist->storage, &error);
+ mailbox_list_set_error(list, error, str);
+ } else {
+ ret = qlist->module_ctx.super.delete_mailbox(list, name);
+ }
+ if (box != NULL)
mailbox_close(&box);
- return -1;
- }
-
- memset(&search_arg, 0, sizeof(search_arg));
- search_arg.type = SEARCH_ALL;
-
- t = mailbox_transaction_begin(box, 0);
- qt = QUOTA_CONTEXT(t);
- ctx = mailbox_search_init(t, NULL, &search_arg, NULL);
-
- mail = mail_alloc(t, 0, NULL);
- while (mailbox_search_next(ctx, mail) > 0)
- quota_free(qt, mail);
- mail_free(&mail);
-
- ret = mailbox_search_deinit(&ctx);
- if (ret < 0)
- mailbox_transaction_rollback(&t);
- else
- ret = mailbox_transaction_commit(&t);
- mailbox_close(&box);
+
/* FIXME: here's an unfortunate race condition */
return ret < 0 ? -1 :
qlist->module_ctx.super.delete_mailbox(list, name);
More information about the dovecot-cvs
mailing list