Diff between e01a82948fa53418aeb4ad011b677fb9660cfbd6 and 87d13379a58ee45c9d29448454666c5831572521

Changed Files

File Additions Deletions Status
tools/mesh/mesh-db.c +18 -6 modified

Full Patch

diff --git a/tools/mesh/mesh-db.c b/tools/mesh/mesh-db.c
index fa12cd2..9b97632 100644
--- a/tools/mesh/mesh-db.c
+++ b/tools/mesh/mesh-db.c
@@ -54,6 +54,9 @@ static bool add_string(json_object *jobj, const char *desc, const char *str)
 	if (!jstring)
 		return false;
 
+	/* Overwrite old value if present */
+	json_object_object_del(jobj, desc);
+
 	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
@@ -69,8 +72,6 @@ static bool set_timestamp(json_object *jobj)
 
 	strftime(buf, 80, "%FT%TZ", tp);
 
-	json_object_object_del(jobj, "timestamp");
-
 	return add_string(jobj, "timestamp", buf);
 }
 
@@ -190,12 +191,13 @@ static bool write_int(json_object *jobj, const char *keyword, int val)
 {
 	json_object *jval;
 
-	json_object_object_del(jobj, keyword);
-
 	jval = json_object_new_int(val);
 	if (!jval)
 		return false;
 
+	/* Overwrite old value if present */
+	json_object_object_del(jobj, keyword);
+
 	json_object_object_add(jobj, keyword, jval);
 	return true;
 }
@@ -222,12 +224,13 @@ static bool write_bool(json_object *jobj, const char *keyword, bool val)
 {
 	json_object *jval;
 
-	json_object_object_del(jobj, keyword);
-
 	jval = json_object_new_boolean(val);
 	if (!jval)
 		return false;
 
+	/* Overwrite old value if present */
+	json_object_object_del(jobj, keyword);
+
 	json_object_object_add(jobj, keyword, jval);
 	return true;
 }
@@ -262,6 +265,9 @@ static bool write_uint16_hex(json_object *jobj, const char *desc,
 	if (!jstring)
 		return false;
 
+	/* Overwrite old value if present */
+	json_object_object_del(jobj, desc);
+
 	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
@@ -327,6 +333,9 @@ static bool add_u8_8(json_object *jobj, const char *desc,
 	if (!jstring)
 		return false;
 
+	/* Overwrite old value if present */
+	json_object_object_del(jobj, desc);
+
 	json_object_object_add(jobj, desc, jstring);
 	return true;
 }
@@ -342,6 +351,9 @@ static bool add_u8_16(json_object *jobj, const char *desc,
 	if (!jstring)
 		return false;
 
+	/* Overwrite old value if present */
+	json_object_object_del(jobj, desc);
+
 	json_object_object_add(jobj, desc, jstring);
 	return true;
 }