# HG changeset patch # User Timo Sirainen # Date 1496999220 -10800 # Node ID 3272674e4e5d929282ec9eae34d8c7968d64ae89 # Parent edc9369f9d60c31a6d7f7abca28fa9a6c2543a8f 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. diff -r edc9369f9d60 -r 3272674e4e5d src/plugins/quota/quota-private.h --- a/src/plugins/quota/quota-private.h Wed May 31 14:39:55 2017 +0300 +++ b/src/plugins/quota/quota-private.h Fri Jun 09 12:07:00 2017 +0300 @@ -135,7 +135,9 @@ /* 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 -r edc9369f9d60 -r 3272674e4e5d src/plugins/quota/quota-storage.c --- a/src/plugins/quota/quota-storage.c Wed May 31 14:39:55 2017 +0300 +++ b/src/plugins/quota/quota-storage.c Fri Jun 09 12:07:00 2017 +0300 @@ -398,8 +398,13 @@ 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 -r edc9369f9d60 -r 3272674e4e5d src/plugins/quota/quota.c --- a/src/plugins/quota/quota.c Wed May 31 14:39:55 2017 +0300 +++ b/src/plugins/quota/quota.c Fri Jun 09 12:07:00 2017 +0300 @@ -1331,10 +1331,10 @@ { 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++;