# HG changeset patch # User Timo Sirainen # Date 1453209319 -7200 # Node ID 51a4c305a0873d290f5a97e445fad7b994fd66f9 # Parent cf3fdf33548433067ca6978a1e59519dc42a71fb 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 -r cf3fdf335484 -r 51a4c305a087 src/plugins/quota-clone/quota-clone-plugin.c --- a/src/plugins/quota-clone/quota-clone-plugin.c Tue Jan 19 15:11:44 2016 +0200 +++ b/src/plugins/quota-clone/quota-clone-plugin.c Tue Jan 19 15:15:19 2016 +0200 @@ -40,8 +40,7 @@ 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 @@ 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