From: Timo Sirainen Date: Tue, 19 Jan 2016 13:15:19 +0000 (+0200) Subject: quota-clone: Avoid leaving a dict transaction open for unnecessarily long. X-Git-Tag: 2.2.22.rc1~327 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d861bc0977b229cdaeb3fb77377e2a2bd9d40d3d;p=thirdparty%2Fdovecot%2Fcore.git quota-clone: Avoid leaving a dict transaction open for unnecessarily long. 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. --- diff --git a/src/plugins/quota-clone/quota-clone-plugin.c b/src/plugins/quota-clone/quota-clone-plugin.c index 76ec96921d..0dbbf72297 100644 --- a/src/plugins/quota-clone/quota-clone-plugin.c +++ b/src/plugins/quota-clone/quota-clone-plugin.c @@ -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