Skip to content

Commit 8ebb6f7

Browse files
committed
data_factory: search for container in data tree only if parent_data is not NULL
Signed-off-by: ali aqrabawi <aaqrabaw@okdanetworks.com>
1 parent be62374 commit 8ebb6f7

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/commands/yang_core/data_factory.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "y_utils.h"
1717
#include "src/onm_logger.h"
1818

19-
2019
struct lyd_node *parent_data = NULL;
2120

2221
void free_parent_data() {
@@ -207,12 +206,17 @@ static int edit_node_data_tree(struct lysc_node *y_node, char *value, int edit_t
207206

208207
int item_found = 1;
209208
// check if the node exist in the tree, if not create new node in the tree.
210-
ret = lyd_find_path(parent_data, xpath, 0, &new_parent);
211-
if (ret == LY_ENOTFOUND)
212-
item_found = 0;
213-
if (new_parent == NULL || ret == LY_EINCOMPLETE) {
209+
if (parent_data == NULL) {
214210
ret = lyd_new_path(parent_data, sysrepo_ctx, xpath, NULL, LYD_NEW_PATH_UPDATE, &new_parent);
211+
} else {
212+
ret = lyd_find_path(parent_data, xpath, 0, &new_parent);
213+
if (ret == LY_ENOTFOUND)
214+
item_found = 0;
215+
if (new_parent == NULL || ret == LY_EINCOMPLETE) {
216+
ret = lyd_new_path(parent_data, sysrepo_ctx, xpath, NULL, LYD_NEW_PATH_UPDATE, &new_parent);
217+
}
215218
}
219+
216220
if (ret != LY_SUCCESS)
217221
break;
218222
// if the edit operation is 'add', then update the parent_node, else (which is 'delete' operation) then just set the out node.
@@ -253,7 +257,7 @@ static int edit_node_data_tree(struct lysc_node *y_node, char *value, int edit_t
253257
if (new_leaf == NULL) {
254258
item_found = 0;
255259
ret = lyd_new_path2(parent_data, sysrepo_ctx, xpath, value, strlen(value), LYD_ANYDATA_STRING,
256-
LYD_NEW_PATH_OUTPUT, NULL, &new_leaf);
260+
0, NULL, &new_leaf);
257261
}
258262

259263

0 commit comments

Comments
 (0)