changeset 14507:ec8564741aa8

quota: Set to quota transaction how many bytes/messages we're over quota.
author Timo Sirainen <tss@iki.fi>
date Tue, 24 Apr 2012 21:03:19 +0300
parents 6607e35dd8d2
children dd3798681283
files src/plugins/quota/quota-private.h src/plugins/quota/quota.c
diffstat 2 files changed, 24 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/quota/quota-private.h	Mon Apr 23 17:59:39 2012 +0300
+++ b/src/plugins/quota/quota-private.h	Tue Apr 24 21:03:19 2012 +0300
@@ -133,6 +133,9 @@
 	/* 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;
+	/* how many bytes/mails we are over quota (either *_ceil or *_over
+	   is always zero) */
+	uint64_t bytes_over, count_over;
 
 	struct mail *tmp_mail;
 
--- a/src/plugins/quota/quota.c	Mon Apr 23 17:59:39 2012 +0300
+++ b/src/plugins/quota/quota.c	Tue Apr 24 21:03:19 2012 +0300
@@ -940,7 +940,7 @@
 	struct quota_root *const *roots;
 	const char *mailbox_name;
 	unsigned int i, count;
-	uint64_t bytes_limit, count_limit, current, limit, ceil;
+	uint64_t bytes_limit, count_limit, current, limit, diff;
 	int ret;
 
 	ctx->limits_set = TRUE;
@@ -964,9 +964,16 @@
 						 QUOTA_NAME_STORAGE_BYTES,
 						 &current, &limit);
 			if (ret > 0) {
-				ceil = limit < current ? 0 : limit - current;
-				if (ctx->bytes_ceil > ceil)
-					ctx->bytes_ceil = ceil;
+				if (limit < current) {
+					ctx->bytes_ceil = 0;
+					diff = current - limit;
+					if (ctx->bytes_over < diff)
+						ctx->bytes_over = diff;
+				} else {
+					diff = limit - current;
+					if (ctx->bytes_ceil > diff)
+						ctx->bytes_ceil = diff;
+				}
 			} else if (ret < 0) {
 				ctx->failed = TRUE;
 				return -1;
@@ -978,9 +985,16 @@
 						 QUOTA_NAME_MESSAGES,
 						 &current, &limit);
 			if (ret > 0) {
-				ceil = limit < current ? 0 : limit - current;
-				if (ctx->count_ceil > ceil)
-					ctx->count_ceil = ceil;
+				if (limit < current) {
+					ctx->count_ceil = 0;
+					diff = current - limit;
+					if (ctx->count_over < diff)
+						ctx->count_over = diff;
+				} else {
+					diff = limit - current;
+					if (ctx->count_ceil > diff)
+						ctx->count_ceil = diff;
+				}
 			} else if (ret < 0) {
 				ctx->failed = TRUE;
 				return -1;