Skip to content

Commit

Permalink
quota-dict: Remove T_BEGIN..T_END blocks
Browse files Browse the repository at this point in the history
This is to enable using t_strdup_printf() with error_r later on.
  • Loading branch information
mrannanj authored and Timo Sirainen committed Oct 19, 2017
1 parent 5997118 commit 5729882
Showing 1 changed file with 34 additions and 38 deletions.
72 changes: 34 additions & 38 deletions src/plugins/quota/quota-dict.c
Expand Up @@ -115,20 +115,18 @@ dict_quota_count(struct dict_quota_root *root,
if (quota_count(&root->root, &bytes, &count) < 0)
return -1;

T_BEGIN {
dt = dict_transaction_begin(root->dict);
/* these unsets are mainly necessary for pgsql, because its
trigger otherwise increases quota without deleting it.
but some people with other databases want to store the
quota usage among other data in the same row, which
shouldn't be deleted. */
if (!root->disable_unset) {
dict_unset(dt, DICT_QUOTA_CURRENT_BYTES_PATH);
dict_unset(dt, DICT_QUOTA_CURRENT_COUNT_PATH);
}
dict_set(dt, DICT_QUOTA_CURRENT_BYTES_PATH, dec2str(bytes));
dict_set(dt, DICT_QUOTA_CURRENT_COUNT_PATH, dec2str(count));
} T_END;
dt = dict_transaction_begin(root->dict);
/* these unsets are mainly necessary for pgsql, because its
trigger otherwise increases quota without deleting it.
but some people with other databases want to store the
quota usage among other data in the same row, which
shouldn't be deleted. */
if (!root->disable_unset) {
dict_unset(dt, DICT_QUOTA_CURRENT_BYTES_PATH);
dict_unset(dt, DICT_QUOTA_CURRENT_COUNT_PATH);
}
dict_set(dt, DICT_QUOTA_CURRENT_BYTES_PATH, dec2str(bytes));
dict_set(dt, DICT_QUOTA_CURRENT_COUNT_PATH, dec2str(count));

if (root->root.quota->set->debug) {
i_debug("dict quota: Quota recalculated: "
Expand All @@ -155,31 +153,29 @@ dict_quota_get_resource(struct quota_root *_root,
else
return 0;

T_BEGIN {
const char *key, *value, *error;

key = want_bytes ? DICT_QUOTA_CURRENT_BYTES_PATH :
DICT_QUOTA_CURRENT_COUNT_PATH;
ret = dict_lookup(root->dict, unsafe_data_stack_pool,
key, &value, &error);
if (ret < 0) {
i_error("dict quota: dict_lookup(%s) failed: %s", key, error);
*value_r = 0;
} else {
intmax_t tmp;

/* recalculate quota if it's negative or if it
wasn't found */
if (ret == 0 || str_to_intmax(value, &tmp) < 0)
tmp = -1;
if (tmp >= 0)
*value_r = tmp;
else {
ret = dict_quota_count(root, want_bytes,
value_r);
}
const char *key, *value, *error;

key = want_bytes ? DICT_QUOTA_CURRENT_BYTES_PATH :
DICT_QUOTA_CURRENT_COUNT_PATH;
ret = dict_lookup(root->dict, unsafe_data_stack_pool,
key, &value, &error);
if (ret < 0) {
i_error("dict quota: dict_lookup(%s) failed: %s", key, error);
*value_r = 0;
} else {
intmax_t tmp;

/* recalculate quota if it's negative or if it
wasn't found */
if (ret == 0 || str_to_intmax(value, &tmp) < 0)
tmp = -1;
if (tmp >= 0)
*value_r = tmp;
else {
ret = dict_quota_count(root, want_bytes,
value_r);
}
} T_END;
}
return ret;
}

Expand Down

0 comments on commit 5729882

Please sign in to comment.