]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota: quota-util - Rework comments in quota_is_over()
authorStephan Bosch <stephan.bosch@open-xchange.com>
Tue, 9 Nov 2021 22:19:23 +0000 (23:19 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 26 Feb 2025 10:45:00 +0000 (10:45 +0000)
src/plugins/quota/quota-util.c

index 5088e3d2962da06468556563b4f8198c2f49cda8..3e83b665048e2fc78b10fa450fa72ec4be70ca05 100644 (file)
@@ -58,32 +58,48 @@ static inline bool
 quota_is_over(uoff_t alloc, int64_t used, uint64_t ceil, uint64_t over)
 {
        if (used < 0) {
+               /* Resource usage decreased in this transaction. */
                const uint64_t deleted = (uint64_t)-used;
 
-               /* we've deleted some messages. */
                if (over > 0) {
+                       /* We were over quota before deleting the messages. */
                        if (over > deleted) {
-                               /* even after deletions we're over quota */
+                               /* We are over quota, even after deletions and
+                                  without the new allocation. */
                                return TRUE;
                        }
-                       if (alloc > (deleted - over))
+                       if (alloc > (deleted - over)) {
+                               /* We are under quota after deletions, but the
+                                  the new allocation exceeds the quota once
+                                  more. */
                                return TRUE;
+                       }
                } else {
-                       if (alloc > deleted && (alloc - deleted) > ceil)
+                       /* We were under quota even before deleting the
+                          messages. */
+                       if (alloc > deleted && (alloc - deleted) > ceil) {
+                               /* The new allocation exceeds the quota limit.
+                                */
                                return TRUE;
+                       }
                }
        } else if (alloc == 0) {
-               /* we need to explicitly test this case, since the generic
-                  check would fail if user is already over quota */
-               if (over > 0)
+               /* Nothing was allocated in this transaction. We need to
+                  explicitly test this case, since the generic check would fail
+                  if user is already over quota. */
+               if (over > 0) {
+                       /* Resource usage is already over quota. */
                        return TRUE;
+               }
        } else {
+               /* Resource usage increased in this transaction. */
                if (ceil < alloc || (ceil - alloc) < (uint64_t)used) {
-                       /* limit reached */
+                       /* Limit reached. */
                        return TRUE;
                }
        }
 
+       /* Not over quota. */
        return FALSE;
 }