dovecot-1.2: quota: Fixed error handling if quota shrinking fail...

dovecot at dovecot.org dovecot at dovecot.org
Tue Aug 12 22:29:30 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/27940e82901e
changeset: 8086:27940e82901e
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Aug 12 15:29:23 2008 -0400
description:
quota: Fixed error handling if quota shrinking fails when deleting a mailbox.

diffstat:

1 file changed, 52 insertions(+), 35 deletions(-)
src/plugins/quota/quota-storage.c |   87 ++++++++++++++++++++++---------------

diffs (111 lines):

diff -r bf83aa9c3f4a -r 27940e82901e src/plugins/quota/quota-storage.c
--- a/src/plugins/quota/quota-storage.c	Tue Aug 12 14:54:27 2008 -0400
+++ b/src/plugins/quota/quota-storage.c	Tue Aug 12 15:29:23 2008 -0400
@@ -386,16 +386,46 @@ 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_args *search_args;
+	int ret;
+
+	if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ, 0, NULL) < 0)
+		return -1;
+
+	t = mailbox_transaction_begin(box, 0);
+	qt = QUOTA_CONTEXT(t);
+
+	search_args = mail_search_build_init();
+	mail_search_build_add_all(search_args);
+	ctx = mailbox_search_init(t, search_args, NULL);
+	mail_search_args_unref(&search_args);
+
+	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
@@ -405,38 +435,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;
-	}
-
-	t = mailbox_transaction_begin(box, 0);
-	qt = QUOTA_CONTEXT(t);
-
-	search_args = mail_search_build_init();
-	mail_search_build_add_all(search_args);
-	ctx = mailbox_search_init(t, search_args, NULL);
-	mail_search_args_unref(&search_args);
-
-	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