Mercurial > dovecot > core-2.2
changeset 12921:230458801916
quota: Code cleanup.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 04 Apr 2011 23:19:01 +0300 |
parents | 618f610c7c67 |
children | 6cc356a5d0a5 |
files | src/plugins/quota/quota-private.h src/plugins/quota/quota.c |
diffstat | 2 files changed, 15 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-private.h Mon Apr 04 23:18:31 2011 +0300 +++ b/src/plugins/quota/quota-private.h Mon Apr 04 23:19:01 2011 +0300 @@ -130,7 +130,9 @@ struct mailbox *box; int64_t bytes_used, count_used; - uint64_t bytes_left, count_left; + /* how many bytes/mails can be saved until limit is reached. + (set once, not updated by bytes_used/count_used) */ + uint64_t bytes_ceil, count_ceil; struct mail *tmp_mail;
--- a/src/plugins/quota/quota.c Mon Apr 04 23:18:31 2011 +0300 +++ b/src/plugins/quota/quota.c Mon Apr 04 23:19:01 2011 +0300 @@ -924,8 +924,8 @@ i_assert(ctx->quota != NULL); ctx->box = box; - ctx->bytes_left = (uint64_t)-1; - ctx->count_left = (uint64_t)-1; + ctx->bytes_ceil = (uint64_t)-1; + ctx->count_ceil = (uint64_t)-1; return ctx; } @@ -934,7 +934,7 @@ struct quota_root *const *roots; const char *mailbox_name; unsigned int i, count; - uint64_t bytes_limit, count_limit, current, limit, left; + uint64_t bytes_limit, count_limit, current, limit, ceil; int ret; ctx->limits_set = TRUE; @@ -958,9 +958,9 @@ QUOTA_NAME_STORAGE_BYTES, ¤t, &limit); if (ret > 0) { - left = limit < current ? 0 : limit - current; - if (ctx->bytes_left > left) - ctx->bytes_left = left; + ceil = limit < current ? 0 : limit - current; + if (ctx->bytes_ceil > ceil) + ctx->bytes_ceil = ceil; } else if (ret < 0) { ctx->failed = TRUE; return -1; @@ -972,9 +972,9 @@ QUOTA_NAME_MESSAGES, ¤t, &limit); if (ret > 0) { - left = limit < current ? 0 : limit - current; - if (ctx->count_left > left) - ctx->count_left = left; + ceil = limit < current ? 0 : limit - current; + if (ctx->count_ceil > ceil) + ctx->count_ceil = ceil; } else if (ret < 0) { ctx->failed = TRUE; return -1; @@ -1170,10 +1170,11 @@ *too_large_r = FALSE; - if ((int64_t)ctx->count_left >= ctx->count_used + 1 && - (int64_t)ctx->bytes_left >= ctx->bytes_used + (off_t)size) + if (ctx->count_used + 1 <= (int64_t)ctx->count_ceil && + ctx->bytes_used + (off_t)size <= (int64_t)ctx->bytes_ceil) return 1; + /* limit reached. only thing left to do now is to set too_large_r. */ roots = array_get(&ctx->quota->roots, &count); for (i = 0; i < count; i++) { uint64_t bytes_limit, count_limit;