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 6be3372b42bbd3c25dac951f663f0bbc2432d49d..9bdd5532b808dbecde909ee1e2b216783797626c 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;
+       bool merge = false;
 
        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;
+               else
+                       merge = true;
        }
        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;
diff --git a/err.h b/err.h
index 358cadfe942f4685d0166c8fa0bb5eb5641666fb..686cde354b5d24fc3886c27a6ca217f3e0815106 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;                  \
+       ctx->errno = 0;                 \
        if (!ctx)                       \
                return UCI_ERR_INVAL;   \
        if (!ctx->internal)             \