int c = UCI_CMD_CHANGE;
switch(**buf) {
+ case '^':
+ c = UCI_CMD_REORDER;
+ break;
case '-':
c = UCI_CMD_REMOVE;
break;
goto error;
switch(c) {
+ case UCI_CMD_REORDER:
+ if (!ptr->value || ptr->option)
+ goto error;
+ break;
case UCI_CMD_RENAME:
if (!ptr->value || !uci_validate_name(ptr->value))
goto error;
uci_add_history(ctx, &p->saved_history, cmd, ptr.section, ptr.option, ptr.value);
switch(cmd) {
+ case UCI_CMD_REORDER:
+ expand_ptr(ctx, &ptr, true);
+ if (!ptr.s)
+ UCI_THROW(ctx, UCI_ERR_NOTFOUND);
+ UCI_INTERNAL(uci_reorder_section, ctx, ptr.s, strtoul(ptr.value, NULL, 10));
+ break;
case UCI_CMD_RENAME:
UCI_INTERNAL(uci_rename, ctx, &ptr);
break;
break;
case UCI_CMD_ADD:
case UCI_CMD_CHANGE:
- UCI_INTERNAL(uci_set, ctx, p, ptr.section, ptr.option, ptr.value, &e);
+ UCI_INTERNAL(uci_set, ctx, &ptr);
+ e = ptr.last;
if (!ptr.option && e && (cmd == UCI_CMD_ADD))
uci_to_section(e)->anonymous = true;
break;
changes = uci_load_history_file(ctx, p, filename, &f, flush);
if (flush && f && (changes > 0)) {
rewind(f);
- ftruncate(fileno(f), 0);
+ if (ftruncate(fileno(f), 0) < 0) {
+ uci_close_stream(f);
+ UCI_THROW(ctx, UCI_ERR_IO);
+ }
}
if (filename)
free(filename);
/* rebuild the history file */
rewind(f);
- ftruncate(fileno(f), 0);
+ if (ftruncate(fileno(f), 0) < 0)
+ UCI_THROW(ctx, UCI_ERR_IO);
uci_foreach_element_safe(&list, tmp, e) {
fprintf(f, "%s\n", e->name);
uci_free_element(e);
done:
if (filename)
free(filename);
- uci_close_stream(f);
+ uci_close_stream(pctx->file);
uci_foreach_element_safe(&list, tmp, e) {
uci_free_element(e);
}
char *option = NULL;
UCI_HANDLE_ERR(ctx);
- expand_ptr(ctx, ptr, true);
+ expand_ptr(ctx, ptr, false);
UCI_ASSERT(ctx, ptr->p->has_history);
/*
/* NB: need to clone package, section and option names,
* as they may get freed on uci_free_package() */
package = uci_strdup(ctx, ptr->p->e.name);
- section = uci_strdup(ctx, ptr->section);
- option = uci_strdup(ctx, ptr->option);
+ if (ptr->section)
+ section = uci_strdup(ctx, ptr->section);
+ if (ptr->option)
+ option = uci_strdup(ctx, ptr->option);
uci_free_package(&ptr->p);
uci_filter_history(ctx, package, section, option);
case UCI_CMD_ADD:
prefix = "+";
break;
+ case UCI_CMD_REORDER:
+ prefix = "^";
+ break;
case UCI_CMD_LIST_ADD:
prefix = "|";
break;