# HG changeset patch # User Timo Sirainen # Date 1436606088 -10800 # Node ID 421f595a0e9383835561a5eab9f9f52b4e65e30c # Parent 84392ca460abc1987927d47e423ff7f1fc8d61a7 quota: Use MAILBOX_METADATA_PHYSICAL_SIZE for recalculating mailbox's size. diff -r 84392ca460ab -r 421f595a0e93 src/plugins/quota/quota-count.c --- a/src/plugins/quota/quota-count.c Sat Jul 11 12:11:48 2015 +0300 +++ b/src/plugins/quota/quota-count.c Sat Jul 11 12:14:48 2015 +0300 @@ -1,27 +1,22 @@ /* Copyright (c) 2006-2015 Dovecot authors, see the included COPYING file */ #include "lib.h" -#include "array.h" -#include "mail-search-build.h" -#include "mail-storage.h" -#include "mail-namespace.h" #include "mailbox-list-iter.h" #include "quota-private.h" +extern struct quota_backend quota_backend_count; + static int quota_count_mailbox(struct quota_root *root, struct mail_namespace *ns, const char *vname, uint64_t *bytes_r, uint64_t *count_r) { struct quota_rule *rule; struct mailbox *box; - struct mailbox_transaction_context *trans; - struct mail_search_context *ctx; - struct mail *mail; - struct mail_search_args *search_args; + struct mailbox_metadata metadata; + struct mailbox_status status; enum mail_error error; const char *errstr; - uoff_t size; - int ret = 0; + int ret; rule = quota_root_rule_find(root->set, vname); if (rule != NULL && rule->ignore) { @@ -30,47 +25,23 @@ } box = mailbox_alloc(ns->list, vname, MAILBOX_FLAG_READONLY); - if (mailbox_sync(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) { + if (mailbox_get_metadata(box, MAILBOX_METADATA_PHYSICAL_SIZE, + &metadata) < 0 || + mailbox_get_status(box, STATUS_MESSAGES, &status) < 0) { errstr = mailbox_get_last_error(box, &error); - mailbox_free(&box); if (error == MAIL_ERROR_TEMP) { - i_error("quota: Couldn't sync mailbox %s: %s", + i_error("quota: Couldn't get physical size of mailbox %s: %s", vname, errstr); - return -1; + ret = -1; + } else { + /* non-temporary error, e.g. ACLs denied access. */ + ret = 0; } - /* non-temporary error, e.g. ACLs denied access. */ - return 0; + } else { + ret = 1; + *bytes_r = metadata.physical_size; + *count_r = status.messages; } - - trans = mailbox_transaction_begin(box, 0); - - search_args = mail_search_build_init(); - mail_search_build_add_all(search_args); - ctx = mailbox_search_init(trans, search_args, NULL, - MAIL_FETCH_PHYSICAL_SIZE, NULL); - mail_search_args_unref(&search_args); - - while (mailbox_search_next(ctx, &mail)) { - if (mail_get_physical_size(mail, &size) == 0) - *bytes_r += size; - else { - errstr = mailbox_get_last_error(box, &error); - if (error != MAIL_ERROR_EXPUNGED) { - i_error("quota: Couldn't get size of mail UID %u in %s: %s", - mail->uid, vname, mailbox_get_last_error(box, NULL)); - ret = -1; - break; - } - } - *count_r += 1; - } - if (mailbox_search_deinit(&ctx) < 0) { - i_error("quota: Listing mails in %s failed: %s", - vname, mailbox_get_last_error(box, NULL)); - ret = -1; - } - (void)mailbox_transaction_commit(&trans); - mailbox_free(&box); return ret; }