allow merge-import, even if the config file does not exist yet
authorFelix Fietkau <nbd@openwrt.org>
Tue, 5 Feb 2008 01:09:25 +0000 (02:09 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Tue, 5 Feb 2008 01:09:25 +0000 (02:09 +0100)
cli.c
err.h

diff --git a/cli.c b/cli.c
index 6be3372..9bdd553 100644 (file)
--- a/cli.c
+++ b/cli.c
@@ -171,6 +171,7 @@ static int uci_do_import(int argc, char **argv)
        struct uci_package *package = NULL;
        char *name = NULL;
        int ret = UCI_OK;
        struct uci_package *package = NULL;
        char *name = NULL;
        int ret = UCI_OK;
+       bool merge = false;
 
        if (argc > 2)
                return 255;
 
        if (argc > 2)
                return 255;
@@ -184,10 +185,12 @@ static int uci_do_import(int argc, char **argv)
        if (flags & CLI_FLAG_MERGE) {
                if (uci_load(ctx, name, &package) != UCI_OK)
                        package = NULL;
        if (flags & CLI_FLAG_MERGE) {
                if (uci_load(ctx, name, &package) != UCI_OK)
                        package = NULL;
+               else
+                       merge = true;
        }
        ret = uci_import(ctx, input, name, &package, (name != NULL));
        if (ret == UCI_OK) {
        }
        ret = uci_import(ctx, input, name, &package, (name != NULL));
        if (ret == UCI_OK) {
-               if (flags & CLI_FLAG_MERGE) {
+               if (merge) {
                        ret = uci_save(ctx, package);
                } else {
                        struct uci_element *e;
                        ret = uci_save(ctx, package);
                } else {
                        struct uci_element *e;
diff --git a/err.h b/err.h
index 358cadf..686cde3 100644 (file)
--- a/err.h
+++ b/err.h
@@ -43,6 +43,7 @@
 #define UCI_HANDLE_ERR(ctx) do {       \
        DPRINTF("ENTER: %s\n", __func__); \
        int __val = 0;                  \
 #define UCI_HANDLE_ERR(ctx) do {       \
        DPRINTF("ENTER: %s\n", __func__); \
        int __val = 0;                  \
+       ctx->errno = 0;                 \
        if (!ctx)                       \
                return UCI_ERR_INVAL;   \
        if (!ctx->internal)             \
        if (!ctx)                       \
                return UCI_ERR_INVAL;   \
        if (!ctx->internal)             \