From b835c5acc4e07ffecbeb0b1cbd7e901f86c2f4c5 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Fri, 9 Jun 2017 12:07:00 +0300 Subject: [PATCH] quota: Fix negative quota_warnings with count backend For example this never triggered: quota_warning = -messages=100%% quota-warning %u -100 The change to quota_alloc() to update the count_used doesn't seem to actually fix anything right now, but it makes the code more correct. --- src/plugins/quota/quota-private.h | 4 +++- src/plugins/quota/quota-storage.c | 7 ++++++- src/plugins/quota/quota.c | 8 ++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/plugins/quota/quota-private.h b/src/plugins/quota/quota-private.h index a869f7101e..e21bac1c56 100644 --- a/src/plugins/quota/quota-private.h +++ b/src/plugins/quota/quota-private.h @@ -135,7 +135,9 @@ struct quota_root { /* don't enforce quota when saving */ unsigned int no_enforcing:1; /* quota is automatically updated. update() should be called but the - bytes/count won't be used. */ + bytes won't be changed. count is still changed, because it's cheap + to do and it's internally used to figure out whether there have + been some changes and that quota_warnings should be checked. */ unsigned int auto_updating:1; /* If user has unlimited quota, disable quota tracking */ unsigned int disable_unlimited_tracking:1; diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index ed4453e56a..52d8f334e3 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -398,8 +398,13 @@ static void quota_mailbox_sync_notify(struct mailbox *box, uint32_t uid, qbox->expunge_qt->sync_transaction = qbox->sync_transaction_expunge; } - if (qbox->expunge_qt->auto_updating) + if (qbox->expunge_qt->auto_updating) { + /* even though backend doesn't care about size/count changes, + make sure count_used changes so quota_warnings are + executed */ + quota_free_bytes(qbox->expunge_qt, 0); return; + } /* we're in the middle of syncing the mailbox, so it's a bad idea to try and get the message sizes at this point. Rely on sizes that diff --git a/src/plugins/quota/quota.c b/src/plugins/quota/quota.c index 8eab687766..36f00c38b8 100644 --- a/src/plugins/quota/quota.c +++ b/src/plugins/quota/quota.c @@ -1331,10 +1331,10 @@ void quota_alloc(struct quota_transaction_context *ctx, struct mail *mail) { uoff_t size; - if (ctx->auto_updating) - return; - if (mail_get_physical_size(mail, &size) == 0) - ctx->bytes_used += size; + if (!ctx->auto_updating) { + if (mail_get_physical_size(mail, &size) == 0) + ctx->bytes_used += size; + } ctx->bytes_ceil = ctx->bytes_ceil2; ctx->count_used++;