]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
quota-clone: Avoid leaving a dict transaction open for unnecessarily long.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 19 Jan 2016 13:15:19 +0000 (15:15 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 19 Jan 2016 13:15:19 +0000 (15:15 +0200)
Even though the earlier change should fix the dict assert crash due to
opening multiple transactions when recursing back, this makes sure of it.
It could also be helpful for some dict backends to not keep the transaction
open for unnecessarily long.

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

index 76ec96921d784fa50e88eccaabb62313abc114b9..0dbbf72297c58c608ab74275a0a927fc0c2ffac2 100644 (file)
@@ -40,8 +40,7 @@ static void quota_clone_flush(struct mailbox *box)
        struct dict_transaction_context *trans;
        struct quota_root_iter *iter;
        struct quota_root *root;
-       uint64_t value, limit;
-       int ret;
+       uint64_t bytes_value, count_value, limit;
 
        /* we'll clone the first quota root */
        iter = quota_root_iter_init(box);
@@ -53,25 +52,24 @@ static void quota_clone_flush(struct mailbox *box)
                return;
        }
 
-       trans = dict_transaction_begin(quser->dict);
-       /* update bytes */
-       ret = quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES,
-                                &value, &limit);
-       if (ret < 0)
+       /* get new values first */
+       if (quota_get_resource(root, "", QUOTA_NAME_STORAGE_BYTES,
+                              &bytes_value, &limit) < 0) {
                i_error("quota_clone_plugin: Failed to lookup current quota bytes");
-       else {
-               dict_set(trans, DICT_QUOTA_CLONE_BYTES_PATH,
-                        t_strdup_printf("%llu", (unsigned long long)value));
+               return;
        }
-       /* update messages */
-       ret = quota_get_resource(root, "", QUOTA_NAME_MESSAGES,
-                                &value, &limit);
-       if (ret < 0)
+       if (quota_get_resource(root, "", QUOTA_NAME_MESSAGES,
+                              &count_value, &limit) < 0) {
                i_error("quota_clone_plugin: Failed to lookup current quota count");
-       else {
-               dict_set(trans, DICT_QUOTA_CLONE_COUNT_PATH,
-                        t_strdup_printf("%llu", (unsigned long long)value));
+               return;
        }
+
+       /* then update them */
+       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 (dict_transaction_commit(&trans) < 0)
                i_error("quota_clone_plugin: Failed to commit dict update");
        else