degesch: finish /set

One bug remaining to make it work.
This commit is contained in:
Přemysl Eric Janouch 2015-05-03 19:11:57 +02:00
parent 1e3a273690
commit 134a627130
2 changed files with 19 additions and 9 deletions

View File

@ -1385,6 +1385,20 @@ end:
return object; return object;
} }
/// Clone an item. Schema assignments aren't retained.
struct config_item_ *
config_item_clone (struct config_item_ *self)
{
// Oh well, it saves code
struct str tmp;
str_init (&tmp);
config_item_write (self, false, &tmp);
struct config_item_ *result =
config_item_parse (tmp.str, tmp.len, true, NULL);
str_free (&tmp);
return result;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX: this thing is ugly in concept // XXX: this thing is ugly in concept

View File

@ -3835,6 +3835,8 @@ handle_command_set_add
struct str_vector items; struct str_vector items;
str_vector_init (&items); str_vector_init (&items);
split_str (item->value.string.str, ',', &items); split_str (item->value.string.str, ',', &items);
if (items.len == 1 && !*items.vector[0])
str_vector_reset (&items);
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);
@ -3856,6 +3858,8 @@ handle_command_set_remove
struct str_vector items; struct str_vector items;
str_vector_init (&items); str_vector_init (&items);
split_str (item->value.string.str, ',', &items); split_str (item->value.string.str, ',', &items);
if (items.len == 1 && !*items.vector[0])
str_vector_reset (&items);
ssize_t i = str_vector_find (&items, value); ssize_t i = str_vector_find (&items, value);
if (i == -1) if (i == -1)
@ -3870,14 +3874,6 @@ handle_command_set_remove
return result; return result;
} }
static bool
handle_command_set_replace (struct app_context *ctx,
struct config_item_ *item, struct config_item_ *new_, struct error **e)
{
// TODO: replace the item (or log error)
return false;
}
static void static void
handle_command_set_assign_item (struct app_context *ctx, handle_command_set_assign_item (struct app_context *ctx,
char *key, struct config_item_ *new_, bool add, bool remove) char *key, struct config_item_ *new_, bool add, bool remove)
@ -3895,7 +3891,7 @@ handle_command_set_assign_item (struct app_context *ctx,
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 else
handle_command_set_replace (ctx, item, new_, &e); config_item_set_from (item, config_item_clone (new_), &e);
if (e) if (e)
{ {