cleanup, move parse_tuple to libuci, add some input validation
[project/uci.git] / file.c
diff --git a/file.c b/file.c
index 412ce13..a78c5a7 100644 (file)
--- a/file.c
+++ b/file.c
@@ -293,14 +293,9 @@ static void uci_switch_config(struct uci_context *ctx)
         * if an older config under the same name exists, unload it
         * ignore errors here, e.g. if the config was not found
         */
-       UCI_TRAP_SAVE(ctx, ignore);
        e = uci_lookup_list(ctx, &ctx->root, name);
        if (e)
-               uci_unload(ctx, uci_to_package(e));
-       UCI_TRAP_RESTORE(ctx);
-ignore:
-       ctx->errno = 0;
-
+               UCI_THROW(ctx, UCI_ERR_DUPLICATE);
        pctx->package = uci_alloc_package(ctx, name);
 }
 
@@ -475,15 +470,14 @@ int uci_export(struct uci_context *ctx, FILE *stream, struct uci_package *packag
        UCI_HANDLE_ERR(ctx);
        UCI_ASSERT(ctx, stream != NULL);
 
-       if (package) {
+       if (package)
                uci_export_package(package, stream, header);
-               goto done;
+       else {
+               uci_foreach_element(&ctx->root, e) {
+                       uci_export_package(uci_to_package(e), stream, header);
+               }
        }
 
-       uci_foreach_element(&ctx->root, e) {
-               uci_export_package(uci_to_package(e), stream, header);
-       }
-done:
        return 0;
 }