Skip to content

Commit

Permalink
quota: Fix negative quota_warnings with count backend
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen committed Jun 12, 2017
1 parent ee339bb commit b835c5a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/plugins/quota/quota-private.h
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion src/plugins/quota/quota-storage.c
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/quota/quota.c
Expand Up @@ -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++;
Expand Down

0 comments on commit b835c5a

Please sign in to comment.