diff BUGFIX keep descendant operations
... when changing their parent oeration.
diff --git a/src/diff.c b/src/diff.c
index 556ac58..16b1f2f 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -290,6 +290,7 @@
struct lyd_node *dup, *siblings, *match = NULL, *diff_parent = NULL, *elem;
const struct lyd_node *parent = NULL;
enum lyd_diff_op cur_op;
+ struct lyd_meta *meta;
assert(diff);
@@ -341,8 +342,19 @@
assert(!lyd_diff_get_op(diff_parent, &cur_op) && (cur_op == LYD_DIFF_OP_NONE));
(void)cur_op;
- /* will be replaced by the new operation */
+ /* will be replaced by the new operation but keep the current op for descendants */
lyd_diff_del_meta(diff_parent, "operation");
+ LY_LIST_FOR(lyd_child_no_keys(diff_parent), elem) {
+ lyd_diff_find_meta(elem, "operation", &meta, NULL);
+ if (meta) {
+ /* explicit operation, fine */
+ continue;
+ }
+
+ /* set the none operation */
+ LY_CHECK_RET(lyd_new_meta(NULL, elem, NULL, "yang:operation", "none", 0, NULL));
+ }
+
dup = diff_parent;
} else {
/* duplicate the subtree (and connect to the diff if possible) */
diff --git a/tests/utests/data/test_diff.c b/tests/utests/data/test_diff.c
index 748c064..4400b5d 100644
--- a/tests/utests/data/test_diff.c
+++ b/tests/utests/data/test_diff.c
@@ -4,7 +4,7 @@
* @author Michal Vasko <mvasko@cesnet.cz>
* @brief tests for lyd_diff()
*
- * Copyright (c) 2020 CESNET, z.s.p.o.
+ * Copyright (c) 2020 - 2023 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@@ -117,6 +117,12 @@
" leaf l2 {\n"
" type int32;\n"
" }\n"
+ ""
+ " container cont {\n"
+ " leaf l3 {\n"
+ " type string;\n"
+ " }\n"
+ " }\n"
" }\n"
""
" leaf-list dllist {\n"
@@ -1077,6 +1083,9 @@
" </ul>\n"
" <ul>\n"
" <l1>c</l1>\n"
+ " <cont>\n"
+ " <l3>val1</l3>\n"
+ " </cont>\n"
" </ul>\n"
" <ul>\n"
" <l1>d</l1>\n"
@@ -1088,6 +1097,9 @@
" <ul>\n"
" <l1>c</l1>\n"
" <l2>3</l2>\n"
+ " <cont>\n"
+ " <l3>val2</l3>\n"
+ " </cont>\n"
" </ul>\n"
" <ul>\n"
" <l1>a</l1>\n"
@@ -1110,6 +1122,9 @@
" <ul>\n"
" <l1>c</l1>\n"
" <l2>3</l2>\n"
+ " <cont>\n"
+ " <l3>val2</l3>\n"
+ " </cont>\n"
" </ul>\n"
" <ul>\n"
" <l1>d</l1>\n"
@@ -1126,6 +1141,9 @@
" <ul yang:operation=\"replace\" yang:key=\"\" yang:orig-key=\"[l1='b']\">\n"
" <l1>c</l1>\n"
" <l2 yang:operation=\"create\">3</l2>\n"
+ " <cont yang:operation=\"none\">\n"
+ " <l3 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"val1\">val2</l3>\n"
+ " </cont>\n"
" </ul>\n"
" <ul yang:operation=\"replace\" yang:key=\"[l1='a']\" yang:orig-key=\"[l1='b']\">\n"
" <l1>d</l1>\n"
@@ -1144,6 +1162,9 @@
" <ul yang:operation=\"replace\" yang:key=\"\" yang:orig-key=\"[l1='b']\">\n"
" <l1>c</l1>\n"
" <l2 yang:operation=\"create\">3</l2>\n"
+ " <cont yang:operation=\"none\">\n"
+ " <l3 yang:operation=\"replace\" yang:orig-default=\"false\" yang:orig-value=\"val1\">val2</l3>\n"
+ " </cont>\n"
" </ul>\n"
" <ul yang:operation=\"replace\" yang:key=\"[l1='a']\" yang:orig-key=\"[l1='b']\">\n"
" <l1>d</l1>\n"