]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota-clone: Don't clone quota resources that aren't enabled.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 8 Jun 2017 17:29:05 +0000 (20:29 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Jun 2017 09:06:35 +0000 (12:06 +0300)
They would always just be zeros anyway, so this makes the update slightly
more efficient. Although practically this only matters with dirsize and
fs quotas, which people generally don't use with quota_clone.

src/plugins/quota-clone/quota-clone-plugin.c

index b49b1912d96e20534e58e17c19a210159c28751f..d755a48f1fe35498259796da724826ef60b81698 100644 (file)
@@ -47,6 +47,8 @@ static void quota_clone_flush_real(struct mailbox *box)
        struct quota_root_iter *iter;
        struct quota_root *root;
        uint64_t bytes_value, count_value, limit;
+       const char *error;
+       int ret_bytes, ret_count;
 
        /* we'll clone the first quota root */
        iter = quota_root_iter_init(box);
@@ -59,23 +61,36 @@ static void quota_clone_flush_real(struct mailbox *box)
        }
 
        /* get new values first */
-       if (quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES,
-                              &bytes_value, &limit) < 0) {
+       ret_bytes = quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES,
+                                      &bytes_value, &limit);
+       if (ret_bytes < 0) {
                i_error("quota_clone_plugin: Failed to lookup current quota bytes");
                return;
        }
-       if (quota_get_resource(root, "", QUOTA_NAME_MESSAGES,
-                              &count_value, &limit) < 0) {
+       ret_count = quota_get_resource(root, "", QUOTA_NAME_MESSAGES,
+                                      &count_value, &limit);
+       if (ret_count < 0) {
                i_error("quota_clone_plugin: Failed to lookup current quota count");
                return;
        }
+       if (ret_bytes == 0 && ret_count == 0) {
+               /* quota isn't enabled - no point in updating it */
+               return;
+       }
 
-       /* then update them */
+       /* Then update the resources that exist. The resources can't really
+          change unless the quota backend is changed, so we don't worry about
+          the special case of ret_count changing between 1 and 0. Note that
+          ret_count==1 also when quota is unlimited. */
        trans = dict_transaction_begin(quser->dict);
-       dict_set(trans, DICT_QUOTA_CLONE_BYTES_PATH,
-                t_strdup_printf("%llu", (unsigned long long)bytes_value));
-       dict_set(trans, DICT_QUOTA_CLONE_COUNT_PATH,
-                t_strdup_printf("%llu", (unsigned long long)count_value));
+       if (ret_bytes > 0) {
+               dict_set(trans, DICT_QUOTA_CLONE_BYTES_PATH,
+                        t_strdup_printf("%llu", (unsigned long long)bytes_value));
+       }
+       if (ret_count > 0) {
+               dict_set(trans, DICT_QUOTA_CLONE_COUNT_PATH,
+                        t_strdup_printf("%llu", (unsigned long long)count_value));
+       }
        if (dict_transaction_commit(&trans) < 0)
                i_error("quota_clone_plugin: Failed to commit dict update");
        else