Skip to content

Commit 6e87d87

Browse files
committed
diff BUGFIX reverse diff with schema-mount data
We need to use a module from the specific context of the data. Fixes sysrepo/sysrepo#3591
1 parent 97ac01c commit 6e87d87

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/diff.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,7 +3079,7 @@ LIBYANG_API_DEF LY_ERR
30793079
lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff)
30803080
{
30813081
LY_ERR rc = LY_SUCCESS;
3082-
const struct lys_module *mod;
3082+
const struct lys_module *mod = NULL;
30833083
struct lyd_node *root, *elem, *iter;
30843084
enum lyd_diff_op op;
30853085

@@ -3093,14 +3093,16 @@ lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff)
30933093
/* duplicate diff */
30943094
LY_CHECK_RET(lyd_dup_siblings(src_diff, NULL, LYD_DUP_RECURSIVE | LYD_DUP_NO_LYDS, diff));
30953095

3096-
/* find module with metadata needed for later */
3097-
mod = ly_ctx_get_module_latest(LYD_CTX(src_diff), "yang");
3098-
LY_CHECK_ERR_GOTO(!mod, LOGINT(LYD_CTX(src_diff)); rc = LY_EINT, cleanup);
3099-
31003096
LY_LIST_FOR(*diff, root) {
31013097
LYD_TREE_DFS_BEGIN(root, elem) {
31023098
/* skip all keys */
31033099
if (!lysc_is_key(elem->schema)) {
3100+
/* find module with metadata needed for later in the current node context */
3101+
if (!mod || (mod->ctx != LYD_CTX(elem))) {
3102+
mod = ly_ctx_get_module_latest(LYD_CTX(elem), "yang");
3103+
LY_CHECK_ERR_GOTO(!mod, LOGINT(LYD_CTX(src_diff)); rc = LY_EINT, cleanup);
3104+
}
3105+
31043106
/* find operation attribute, if any */
31053107
LY_CHECK_GOTO(rc = lyd_diff_get_op(elem, &op, NULL), cleanup);
31063108

0 commit comments

Comments
 (0)