]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: quota-util - Add quota_used_apply_expunged()
authorStephan Bosch <stephan.bosch@open-xchange.com>
Thu, 13 Feb 2025 01:19:36 +0000 (02:19 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 26 Feb 2025 10:45:00 +0000 (10:45 +0000)
src/plugins/quota/quota-private.h
src/plugins/quota/quota-util.c

index ec53087a0818f10a6929caef32ca0a812977c660..f532e8334063a4a422c2924bca33c7e379c93d88 100644 (file)
@@ -167,6 +167,7 @@ bool quota_warning_match(const struct quota_root_settings *w,
 
 int quota_get_mail_size(struct quota_transaction_context *ctx,
                        struct mail *mail, uoff_t *size_r);
+void quota_used_apply_expunged(int64_t *used, uint64_t expunged);
 bool quota_transaction_is_over(struct quota_transaction_context *ctx, uoff_t size);
 bool quota_root_is_over(struct quota_transaction_context *ctx,
                        struct quota_transaction_root_context *root,
index 64c8e9eb58585b0030e11453bc9df3419a244d2c..4435f9417f6b68ae7852e91ab2fb14f322905465 100644 (file)
@@ -119,6 +119,29 @@ quota_is_over(uoff_t alloc, int64_t used, uint64_t ceil, uint64_t over,
        return FALSE;
 }
 
+void quota_used_apply_expunged(int64_t *used, uint64_t expunged)
+{
+       int64_t exp_signed;
+       int64_t exp_overflow;
+
+       if (expunged < (uint64_t)INT64_MAX) {
+               exp_overflow = 0;
+               exp_signed = (int64_t)expunged;
+       } else {
+               exp_overflow = (int64_t)(expunged - INT64_MAX);
+               exp_signed = INT64_MAX;
+       }
+
+       if (INT64_MIN + exp_signed > *used)
+               *used = INT64_MIN;
+       else
+               *used -= exp_signed;
+       if (INT64_MIN + (int64_t)exp_overflow > *used)
+               *used = INT64_MIN;
+       else
+               *used -= exp_overflow;
+}
+
 bool quota_transaction_is_over(struct quota_transaction_context *ctx,
                               uoff_t size)
 {