degesch: fix +=/-= to null config items
This commit is contained in:
parent
4b10ea7ab0
commit
17804fa49b
15
degesch.c
15
degesch.c
|
@ -9347,13 +9347,15 @@ static bool
|
||||||
handle_command_set_add
|
handle_command_set_add
|
||||||
(struct config_item *item, const char *value, struct error **e)
|
(struct config_item *item, const char *value, struct error **e)
|
||||||
{
|
{
|
||||||
bool result = false;
|
|
||||||
struct str_vector items;
|
struct str_vector items;
|
||||||
str_vector_init (&items);
|
str_vector_init (&items);
|
||||||
|
if (item->type != CONFIG_ITEM_NULL)
|
||||||
cstr_split (item->value.string.str, ",", &items);
|
cstr_split (item->value.string.str, ",", &items);
|
||||||
if (items.len == 1 && !*items.vector[0])
|
if (items.len == 1 && !*items.vector[0])
|
||||||
str_vector_reset (&items);
|
str_vector_reset (&items);
|
||||||
|
|
||||||
|
// FIXME: handle multiple items properly
|
||||||
|
bool result = false;
|
||||||
if (str_vector_find (&items, value) != -1)
|
if (str_vector_find (&items, value) != -1)
|
||||||
error_set (e, "already present in the array: %s", value);
|
error_set (e, "already present in the array: %s", value);
|
||||||
else
|
else
|
||||||
|
@ -9370,13 +9372,15 @@ static bool
|
||||||
handle_command_set_remove
|
handle_command_set_remove
|
||||||
(struct config_item *item, const char *value, struct error **e)
|
(struct config_item *item, const char *value, struct error **e)
|
||||||
{
|
{
|
||||||
bool result = false;
|
|
||||||
struct str_vector items;
|
struct str_vector items;
|
||||||
str_vector_init (&items);
|
str_vector_init (&items);
|
||||||
|
if (item->type != CONFIG_ITEM_NULL)
|
||||||
cstr_split (item->value.string.str, ",", &items);
|
cstr_split (item->value.string.str, ",", &items);
|
||||||
if (items.len == 1 && !*items.vector[0])
|
if (items.len == 1 && !*items.vector[0])
|
||||||
str_vector_reset (&items);
|
str_vector_reset (&items);
|
||||||
|
|
||||||
|
// FIXME: handle multiple items properly
|
||||||
|
bool result = false;
|
||||||
ssize_t i = str_vector_find (&items, value);
|
ssize_t i = str_vector_find (&items, value);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
error_set (e, "not present in the array: %s", value);
|
error_set (e, "not present in the array: %s", value);
|
||||||
|
@ -9401,15 +9405,14 @@ handle_command_set_assign_item (struct app_context *ctx,
|
||||||
struct error *e = NULL;
|
struct error *e = NULL;
|
||||||
if (!item->schema)
|
if (!item->schema)
|
||||||
error_set (&e, "option not recognized");
|
error_set (&e, "option not recognized");
|
||||||
else if ((add | remove) && item->type != CONFIG_ITEM_STRING_ARRAY)
|
else if (!add && !remove)
|
||||||
// FIXME: it can also be null, which makes this message confusing
|
config_item_set_from (item, config_item_clone (new_), &e);
|
||||||
|
else if (item->schema->type != CONFIG_ITEM_STRING_ARRAY)
|
||||||
error_set (&e, "not a string array");
|
error_set (&e, "not a string array");
|
||||||
else if (add)
|
else if (add)
|
||||||
handle_command_set_add (item, new_->value.string.str, &e);
|
handle_command_set_add (item, new_->value.string.str, &e);
|
||||||
else if (remove)
|
else if (remove)
|
||||||
handle_command_set_remove (item, new_->value.string.str, &e);
|
handle_command_set_remove (item, new_->value.string.str, &e);
|
||||||
else
|
|
||||||
config_item_set_from (item, config_item_clone (new_), &e);
|
|
||||||
|
|
||||||
if (e)
|
if (e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue