remove internal usage of redundant uci_ptr.last
[project/uci.git] / delta.c
diff --git a/delta.c b/delta.c
index a131e3a6ca9bba2927f1d6aee5c051bee3faed4d..5437fc1c4794291ef9c0d492fd7ef50cb14ba3f5 100644 (file)
--- a/delta.c
+++ b/delta.c
@@ -213,7 +213,6 @@ error:
 
 static void uci_parse_delta_line(struct uci_context *ctx, struct uci_package *p)
 {
-       struct uci_element *e = NULL;
        struct uci_ptr ptr;
        int cmd;
 
@@ -244,11 +243,14 @@ static void uci_parse_delta_line(struct uci_context *ctx, struct uci_package *p)
                UCI_INTERNAL(uci_del_list, ctx, &ptr);
                break;
        case UCI_CMD_ADD:
+               UCI_INTERNAL(uci_set, ctx, &ptr);
+               if (!ptr.option && ptr.s)
+                       ptr.s->anonymous = true;
+               break;
        case UCI_CMD_CHANGE:
                UCI_INTERNAL(uci_set, ctx, &ptr);
-               e = ptr.last;
-               if (!ptr.option && e && (cmd == UCI_CMD_ADD))
-                       uci_to_section(e)->anonymous = true;
+               break;
+       default:
                break;
        }
        return;
@@ -293,7 +295,7 @@ error:
 }
 
 /* returns the number of changes that were successfully parsed */
-static int uci_load_delta_file(struct uci_context *ctx, struct uci_package *p, char *filename, FILE **f, bool flush)
+static int uci_load_delta_file(struct uci_context *ctx, struct uci_package *p, char *filename, FILE *volatile *f, bool flush)
 {
        FILE *volatile stream = NULL;
        volatile int changes = 0;
@@ -334,9 +336,7 @@ __private int uci_load_delta(struct uci_context *ctx, struct uci_package *p, boo
 
        if ((asprintf(&filename, "%s/%s", ctx->savedir, p->e.name) < 0) || !filename)
                UCI_THROW(ctx, UCI_ERR_MEM);
-       UCI_TRAP_SAVE(ctx, done);
-       f = uci_open_stream(ctx, filename, NULL, SEEK_SET, flush, false);
-       UCI_TRAP_RESTORE(ctx);
+       uci_load_delta_file(ctx, NULL, filename, &f, flush);
 
        if (flush && f && (changes > 0)) {
                if (ftruncate(fileno(f), 0) < 0) {
@@ -346,7 +346,6 @@ __private int uci_load_delta(struct uci_context *ctx, struct uci_package *p, boo
                }
        }
 
-done:
        free(filename);
        uci_close_stream(f);
        ctx->err = 0;
@@ -392,7 +391,7 @@ static void uci_filter_delta(struct uci_context *ctx, const char *name, const ch
                                match = false;
                }
 
-               if (!match) {
+               if (!match && ptr.section) {
                        uci_add_delta(ctx, &list, c,
                                ptr.section, ptr.option, ptr.value);
                }