changeset 19593:51a4c305a087

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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 19 Jan 2016 15:15:19 +0200
parents cf3fdf335484
children 30d1d947b589
files src/plugins/quota-clone/quota-clone-plugin.c
diffstat 1 files changed, 15 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- 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