+ 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);
+