- UCI_HANDLE_ERR(ctx);
- UCI_ASSERT(ctx, package != NULL);
- p = *package;
-
- UCI_ASSERT(ctx, p != NULL);
- UCI_ASSERT(ctx, p->path != NULL);
-
- /* open the config file for writing now, so that it is locked */
- f = uci_open_stream(ctx, p->path, SEEK_SET, true, true);
-
- /* flush unsaved changes and reload from history file */
- UCI_TRAP_SAVE(ctx, done);
- if (p->confdir) {
- name = uci_strdup(ctx, p->e.name);
- path = uci_strdup(ctx, p->path);
- if (!uci_list_empty(&p->history))
- UCI_INTERNAL(uci_save, ctx, p);
- uci_free_package(&p);
- uci_file_cleanup(ctx);
- UCI_INTERNAL(uci_import, ctx, f, name, &p, true);
-
- p->path = path;
- p->confdir = true;
- *package = p;
-
- /* freed together with the uci_package */
- path = NULL;
-
- /* check for updated history, just in case */
- uci_load_history(ctx, p, true);
- }
-
- rewind(f);
- ftruncate(fileno(f), 0);
-
- uci_export(ctx, f, p, false);