changeset 22334:985aa5b0546b

quota: Fix negative storage-based quota_warnings to work with count backend Finishes f9362223346d10a5866b376ed227b77b26ea4292, which fixed it for "messages" but not for "storage".
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 13 Jul 2017 03:15:36 +0300
parents 6af385105911
children 510ee47cc21f
files src/plugins/quota/quota-private.h src/plugins/quota/quota-util.c src/plugins/quota/quota.c
diffstat 3 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/quota/quota-private.h	Thu Jul 13 02:56:33 2017 +0300
+++ b/src/plugins/quota/quota-private.h	Thu Jul 13 03:15:36 2017 +0300
@@ -102,6 +102,8 @@
 
 	/* Limits in default_rule override backend's quota limits */
 	unsigned int force_default_rule:1;
+	/* TRUE if any of the warning_rules have reverse==TRUE */
+	unsigned int have_reverse_warnings:1;
 };
 
 struct quota_root {
--- a/src/plugins/quota/quota-util.c	Thu Jul 13 02:56:33 2017 +0300
+++ b/src/plugins/quota/quota-util.c	Thu Jul 13 03:15:36 2017 +0300
@@ -336,6 +336,8 @@
 	warning->command = p_strdup(root_set->set->pool, p+1);
 	warning->rule = rule;
 	warning->reverse = reverse;
+	if (reverse)
+		root_set->have_reverse_warnings = TRUE;
 
 	quota_root_recalculate_relative_rules(root_set,
 					      root_set->default_rule.bytes_limit,
--- a/src/plugins/quota/quota.c	Thu Jul 13 02:56:33 2017 +0300
+++ b/src/plugins/quota/quota.c	Thu Jul 13 03:15:36 2017 +0300
@@ -858,7 +858,13 @@
 			continue;
 		}
 
-		if (!(*rootp)->auto_updating)
+		/* If there are reverse quota_warnings, we'll need to track
+		   how many bytes were expunged even with auto_updating roots.
+		   (An alternative could be to get the current quota usage
+		   before and after the expunges, but that's more complicated
+		   and probably isn't any better.) */
+		if (!(*rootp)->auto_updating ||
+		    (*rootp)->set->have_reverse_warnings)
 			ctx->auto_updating = FALSE;
 	}