From: Markus Valentin Date: Mon, 1 Feb 2021 14:38:49 +0000 (+0100) Subject: acl: acl_lookup_dict_rebuild_update() - Commit transaction after each [un]set X-Git-Tag: 2.3.15~392 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bfa7433bfcf538af7c4fdafe37a88bde6508c751;p=thirdparty%2Fdovecot%2Fcore.git acl: acl_lookup_dict_rebuild_update() - Commit transaction after each [un]set When used with Cassandra an error can occur if multiple changes are included into one transaction: "Multiple changes in transaction not supported". Prevent these errors by committing every change on it's own. --- diff --git a/src/plugins/acl/acl-lookup-dict.c b/src/plugins/acl/acl-lookup-dict.c index d9a2ae954b..580bbc697b 100644 --- a/src/plugins/acl/acl-lookup-dict.c +++ b/src/plugins/acl/acl-lookup-dict.c @@ -190,7 +190,6 @@ acl_lookup_dict_rebuild_update(struct acl_lookup_dict *dict, path = t_str_new(256); str_append(path, prefix); - dt = dict_transaction_begin(dict->dict); old_ids = array_get(&old_ids_arr, &old_count); new_ids = array_get(new_ids_arr, &new_count); for (newi = oldi = 0; newi < new_count || oldi < old_count; ) { @@ -203,6 +202,7 @@ acl_lookup_dict_rebuild_update(struct acl_lookup_dict *dict, /* new identifier, add it */ str_truncate(path, prefix_len); str_append(path, new_ids[newi]); + dt = dict_transaction_begin(dict->dict); dict_set(dt, str_c(path), "1"); newi++; } else if (!no_removes) { @@ -211,13 +211,15 @@ acl_lookup_dict_rebuild_update(struct acl_lookup_dict *dict, str_append(path, old_ids[oldi]); str_append_c(path, '/'); str_append(path, username); + dt = dict_transaction_begin(dict->dict); dict_unset(dt, str_c(path)); oldi++; } - } - if (dict_transaction_commit(&dt, &error) < 0) { - i_error("acl: dict commit failed: %s", error); - return -1; + if (dt != NULL && dict_transaction_commit(&dt, &error) < 0) { + i_error("acl: dict commit failed: %s", error); + return -1; + } + i_assert(dt == NULL); } return 0; }