Skip to content

Commit a7e92ec

Browse files
committed
validation BUGFIX when can remove NP containers
1 parent 0a7e3a6 commit a7e92ec

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/validation.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ lyd_validate_node_when(const struct lyd_node *tree, const struct lyd_node *node,
194194
* @param[in,out] first First sibling, is updated if needed.
195195
* @param[in] del Node instance to delete.
196196
* @param[in] mod Module of the siblings, NULL for nested siblings.
197+
* @param[in] np_cont_diff Whether to put NP container into diff or only its children.
197198
* @param[in,out] node Optional current iteration node, update it if it is deleted.
198199
* @param[in,out] node_when Optional set with nodes with "when" conditions, may be removed from.
199200
* @param[in,out] diff Validation diff.
@@ -202,7 +203,7 @@ lyd_validate_node_when(const struct lyd_node *tree, const struct lyd_node *node,
202203
*/
203204
static ly_bool
204205
lyd_validate_autodel_node_del(struct lyd_node **first, struct lyd_node *del, const struct lys_module *mod,
205-
struct lyd_node **node, struct ly_set *node_types, struct lyd_node **diff)
206+
int np_cont_diff, struct lyd_node **node, struct ly_set *node_types, struct lyd_node **diff)
206207
{
207208
struct lyd_node *iter;
208209
ly_bool node_autodel = 0;
@@ -217,7 +218,7 @@ lyd_validate_autodel_node_del(struct lyd_node **first, struct lyd_node *del, con
217218

218219
if (diff) {
219220
/* add into diff */
220-
if ((del->schema->nodetype == LYS_CONTAINER) && !(del->schema->flags & LYS_PRESENCE)) {
221+
if (!np_cont_diff && (del->schema->nodetype == LYS_CONTAINER) && !(del->schema->flags & LYS_PRESENCE)) {
221222
/* we do not want to track NP container changes, but remember any removed children */
222223
LY_LIST_FOR(lyd_child(del), iter) {
223224
lyd_val_diff_add(iter, LYD_DIFF_OP_DELETE, diff);
@@ -284,7 +285,7 @@ lyd_validate_unres_when(struct lyd_node **tree, const struct lys_module *mod, st
284285
/* when false */
285286
if (node->flags & LYD_WHEN_TRUE) {
286287
/* autodelete */
287-
lyd_validate_autodel_node_del(tree, node, mod, NULL, node_types, diff);
288+
lyd_validate_autodel_node_del(tree, node, mod, 1, NULL, node_types, diff);
288289
} else if (val_opts & LYD_VALIDATE_OPERATIONAL) {
289290
/* only a warning */
290291
LOGWRN(LYD_CTX(node), "When condition \"%s\" not satisfied.", disabled->cond->expr);
@@ -639,7 +640,7 @@ lyd_validate_autodel_leaflist_dflt(struct lyd_node **first, struct lyd_node **no
639640
LYD_LIST_FOR_INST_SAFE(*first, schema, next, iter) {
640641
if (iter->flags & LYD_DEFAULT) {
641642
/* default instance found, remove it */
642-
if (lyd_validate_autodel_node_del(first, iter, mod, node, NULL, diff)) {
643+
if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, diff)) {
643644
node_autodel = 1;
644645
}
645646
}
@@ -684,7 +685,7 @@ lyd_validate_autodel_cont_leaf_dflt(struct lyd_node **first, struct lyd_node **n
684685
LYD_LIST_FOR_INST_SAFE(*first, schema, next, iter) {
685686
if (iter->flags & LYD_DEFAULT) {
686687
/* default instance, remove it */
687-
if (lyd_validate_autodel_node_del(first, iter, mod, node, NULL, diff)) {
688+
if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, diff)) {
688689
node_autodel = 1;
689690
}
690691
}
@@ -694,7 +695,7 @@ lyd_validate_autodel_cont_leaf_dflt(struct lyd_node **first, struct lyd_node **n
694695
LYD_LIST_FOR_INST(*first, schema, iter) {
695696
if ((iter->flags & LYD_DEFAULT) && !(iter->flags & LYD_NEW)) {
696697
/* old default instance, remove it */
697-
if (lyd_validate_autodel_node_del(first, iter, mod, node, NULL, diff)) {
698+
if (lyd_validate_autodel_node_del(first, iter, mod, 0, node, NULL, diff)) {
698699
node_autodel = 1;
699700
}
700701
break;
@@ -752,7 +753,7 @@ lyd_validate_autodel_case_dflt(struct lyd_node **first, struct lyd_node **node,
752753
if (!iter) {
753754
/* there are only default nodes of the case meaning it does not exist and neither should any default nodes
754755
* of the case, remove this one default node */
755-
if (lyd_validate_autodel_node_del(first, *node, mod, node, NULL, diff)) {
756+
if (lyd_validate_autodel_node_del(first, *node, mod, 0, node, NULL, diff)) {
756757
node_autodel = 1;
757758
}
758759
}

0 commit comments

Comments
 (0)