Skip to content

Commit 2a141b3

Browse files
committed
diff BUGFIX merge replaye op for none op of leaf
Fixes sysrepo/sysrepo#3211
1 parent 1ef66d4 commit 2a141b3

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

src/diff.c

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,28 +1534,43 @@ lyd_diff_merge_replace(struct lyd_node *diff_match, enum lyd_diff_op cur_op, con
15341534
}
15351535
break;
15361536
case LYD_DIFF_OP_NONE:
1537-
/* it is moved now */
1538-
assert(lysc_is_userordered(diff_match->schema) && (diff_match->schema->nodetype == LYS_LIST));
1537+
switch (diff_match->schema->nodetype) {
1538+
case LYS_LIST:
1539+
/* it is moved now */
1540+
assert(lysc_is_userordered(diff_match->schema));
15391541

1540-
/* change the operation */
1541-
LY_CHECK_RET(lyd_diff_change_op(diff_match, LYD_DIFF_OP_REPLACE));
1542+
/* change the operation */
1543+
LY_CHECK_RET(lyd_diff_change_op(diff_match, LYD_DIFF_OP_REPLACE));
15421544

1543-
/* set orig-meta and meta */
1544-
if (lysc_is_dup_inst_list(diff_match->schema)) {
1545-
meta_name = "position";
1546-
orig_meta_name = "orig-position";
1547-
} else {
1548-
meta_name = "key";
1549-
orig_meta_name = "orig-key";
1550-
}
1545+
/* set orig-meta and meta */
1546+
if (lysc_is_dup_inst_list(diff_match->schema)) {
1547+
meta_name = "position";
1548+
orig_meta_name = "orig-position";
1549+
} else {
1550+
meta_name = "key";
1551+
orig_meta_name = "orig-key";
1552+
}
15511553

1552-
meta = lyd_find_meta(src_diff->meta, mod, orig_meta_name);
1553-
LY_CHECK_ERR_RET(!meta, LOGERR_META(ctx, orig_meta_name, src_diff), LY_EINVAL);
1554-
LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
1554+
meta = lyd_find_meta(src_diff->meta, mod, orig_meta_name);
1555+
LY_CHECK_ERR_RET(!meta, LOGERR_META(ctx, orig_meta_name, src_diff), LY_EINVAL);
1556+
LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
15551557

1556-
meta = lyd_find_meta(src_diff->meta, mod, meta_name);
1557-
LY_CHECK_ERR_RET(!meta, LOGERR_META(ctx, meta_name, src_diff), LY_EINVAL);
1558-
LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
1558+
meta = lyd_find_meta(src_diff->meta, mod, meta_name);
1559+
LY_CHECK_ERR_RET(!meta, LOGERR_META(ctx, meta_name, src_diff), LY_EINVAL);
1560+
LY_CHECK_RET(lyd_dup_meta_single(meta, diff_match, NULL));
1561+
break;
1562+
case LYS_LEAF:
1563+
/* only dflt flag changed, now value changed as well, update the operation */
1564+
LY_CHECK_RET(lyd_diff_change_op(diff_match, LYD_DIFF_OP_REPLACE));
1565+
1566+
/* modify the node value */
1567+
if (lyd_change_term(diff_match, lyd_get_value(src_diff))) {
1568+
LOGINT_RET(LYD_CTX(src_diff));
1569+
}
1570+
break;
1571+
default:
1572+
LOGINT_RET(LYD_CTX(src_diff));
1573+
}
15591574
break;
15601575
default:
15611576
/* delete operation is not valid */

0 commit comments

Comments
 (0)