Browse Source

fix uci_set

Felix Fietkau 16 years ago
parent
commit
7ca5c675d7
5 changed files with 11 additions and 13 deletions
  1. 3 4
      file.c
  2. 3 3
      history.c
  3. 4 4
      list.c
  4. 1 1
      uci.h
  5. 0 1
      util.c

+ 3 - 4
file.c

@@ -293,7 +293,6 @@ int uci_import(struct uci_context *ctx, FILE *stream, const char *name, struct u
 	UCI_HANDLE_ERR(ctx);
 
 	/* make sure no memory from previous parse attempts is leaked */
-	ctx->internal = true;
 	uci_cleanup(ctx);
 
 	uci_alloc_parse_context(ctx);
@@ -375,7 +374,7 @@ void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool
 
 	/* flush unsaved changes and reload from history file */
 	UCI_TRAP_SAVE(ctx, done);
-	if (p->confdir) {
+	if (p->has_history) {
 		if (!overwrite) {
 			name = uci_strdup(ctx, p->e.name);
 			path = uci_strdup(ctx, p->path);
@@ -392,7 +391,7 @@ void uci_file_commit(struct uci_context *ctx, struct uci_package **package, bool
 			UCI_INTERNAL(uci_import, ctx, f, name, &p, true);
 
 			p->path = path;
-			p->confdir = true;
+			p->has_history = true;
 			*package = p;
 
 			/* freed together with the uci_package */
@@ -517,7 +516,7 @@ static struct uci_package *uci_file_load(struct uci_context *ctx, const char *na
 
 	if (package) {
 		package->path = filename;
-		package->confdir = confdir;
+		package->has_history = confdir;
 		uci_load_history(ctx, package, false);
 	}
 

+ 3 - 3
history.c

@@ -217,7 +217,7 @@ static int uci_load_history(struct uci_context *ctx, struct uci_package *p, bool
 	FILE *f = NULL;
 	int changes = 0;
 
-	if (!p->confdir)
+	if (!p->has_history)
 		return 0;
 
 	uci_foreach_element(&ctx->history_path, e) {
@@ -321,7 +321,7 @@ int uci_revert(struct uci_context *ctx, struct uci_package **pkg, char *section,
 	UCI_ASSERT(ctx, pkg != NULL);
 	p = *pkg;
 	UCI_ASSERT(ctx, p != NULL);
-	UCI_ASSERT(ctx, p->confdir);
+	UCI_ASSERT(ctx, p->has_history);
 
 	/* 
 	 * - flush unwritten changes
@@ -365,7 +365,7 @@ int uci_save(struct uci_context *ctx, struct uci_package *p)
 	 * directly.
 	 * does not modify the uci_package pointer
 	 */
-	if (!p->confdir)
+	if (!p->has_history)
 		return uci_commit(ctx, &p, false);
 
 	if (uci_list_empty(&p->history))

+ 4 - 4
list.c

@@ -291,7 +291,7 @@ int uci_del_element(struct uci_context *ctx, struct uci_element *e)
 	}
 
 	p = s->package;
-	if (!internal && p->confdir)
+	if (!internal && p->has_history)
 		uci_add_history(ctx, &p->history, UCI_CMD_REMOVE, s->e.name, option, NULL);
 
 	switch(e->type) {
@@ -354,7 +354,7 @@ int uci_set_element_value(struct uci_context *ctx, struct uci_element **element,
 		return 0;
 	}
 	p = s->package;
-	if (!internal && p->confdir)
+	if (!internal && p->has_history)
 		uci_add_history(ctx, &p->history, UCI_CMD_CHANGE, section, option, value);
 
 	uci_list_del(&e->list);
@@ -388,7 +388,7 @@ int uci_rename(struct uci_context *ctx, struct uci_package *p, char *section, ch
 	/* NB: p, section, option validated by uci_lookup */
 	UCI_INTERNAL(uci_lookup, ctx, &e, p, section, option);
 
-	if (!internal && p->confdir)
+	if (!internal && p->has_history)
 		uci_add_history(ctx, &p->history, UCI_CMD_RENAME, section, option, name);
 
 	name = uci_strdup(ctx, name);
@@ -493,7 +493,7 @@ notfound:
 		UCI_THROW(ctx, UCI_ERR_NOTFOUND);
 
 	/* now add the missing entry */
-	if (!internal && p->confdir)
+	if (!internal && p->has_history)
 		uci_add_history(ctx, &p->history, UCI_CMD_CHANGE, section, option, value);
 	if (s) {
 		o = uci_alloc_option(s, option, value);

+ 1 - 1
uci.h

@@ -341,7 +341,7 @@ struct uci_package
 	struct uci_element e;
 	struct uci_list sections;
 	struct uci_context *ctx;
-	bool confdir;
+	bool has_history;
 	char *path;
 
 	/* private: */

+ 0 - 1
util.c

@@ -371,7 +371,6 @@ int uci_parse_argument(struct uci_context *ctx, FILE *stream, char **str, char *
 
 	if (ctx->pctx) {
 		if (ctx->pctx->file != stream) {
-			ctx->internal = true;
 			uci_cleanup(ctx);
 		}
 	} else {