Skip to content

Commit 838829d

Browse files
committed
tree data UPDATE additional support for opaque nodes
1 parent da09abf commit 838829d

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

src/path.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,7 @@ ly_path_compile_leafref(const struct ly_ctx *ctx, const struct lysc_node *ctx_no
12861286

12871287
LY_ERR
12881288
ly_path_eval_partial(const struct ly_path *path, const struct lyd_node *start, const struct lyxp_var *vars,
1289-
LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match)
1289+
ly_bool with_opaq, LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match)
12901290
{
12911291
LY_ARRAY_COUNT_TYPE u;
12921292
struct lyd_node *prev_node = NULL, *elem, *node = NULL, *target;
@@ -1338,7 +1338,13 @@ ly_path_eval_partial(const struct ly_path *path, const struct lyd_node *start, c
13381338
}
13391339
} else {
13401340
/* we will use hashes to find one any/container/leaf instance */
1341-
lyd_find_sibling_val(start, path[u].node, NULL, 0, &node);
1341+
if (lyd_find_sibling_val(start, path[u].node, NULL, 0, &node) && with_opaq) {
1342+
if (!lyd_find_sibling_opaq_next(start, path[u].node->name, &node) &&
1343+
(lyd_node_module(node) != path[u].node->module)) {
1344+
/* non-matching opaque node */
1345+
node = NULL;
1346+
}
1347+
}
13421348
}
13431349

13441350
if (!node) {
@@ -1390,7 +1396,7 @@ ly_path_eval(const struct ly_path *path, const struct lyd_node *start, const str
13901396
LY_ERR ret;
13911397
struct lyd_node *m;
13921398

1393-
ret = ly_path_eval_partial(path, start, vars, NULL, &m);
1399+
ret = ly_path_eval_partial(path, start, vars, 0, NULL, &m);
13941400

13951401
if (ret == LY_SUCCESS) {
13961402
/* last node was found */

src/path.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ LY_ERR ly_path_compile_predicate(const struct ly_ctx *ctx, const struct lysc_nod
211211
* @param[in] path Path structure specifying the target.
212212
* @param[in] start Starting node for relative paths, can be any for absolute paths.
213213
* @param[in] vars Array of defined variables to use in predicates, may be NULL.
214+
* @param[in] with_opaq Whether to consider opaque nodes or not.
214215
* @param[out] path_idx Last found path segment index, can be NULL, set to 0 if not found.
215216
* @param[out] match Last found matching node, can be NULL, set to NULL if not found.
216217
* @return LY_ENOTFOUND if no nodes were found,
@@ -219,7 +220,7 @@ LY_ERR ly_path_compile_predicate(const struct ly_ctx *ctx, const struct lysc_nod
219220
* @return LY_ERR on another error.
220221
*/
221222
LY_ERR ly_path_eval_partial(const struct ly_path *path, const struct lyd_node *start, const struct lyxp_var *vars,
222-
LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match);
223+
ly_bool with_opaq, LY_ARRAY_COUNT_TYPE *path_idx, struct lyd_node **match);
223224

224225
/**
225226
* @brief Resolve the target defined by ly_path structure. Not supported for leafref!

src/tree_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3024,7 +3024,7 @@ lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output,
30243024
LY_CHECK_GOTO(ret, cleanup);
30253025

30263026
/* evaluate the path */
3027-
ret = ly_path_eval_partial(lypath, ctx_node, NULL, NULL, match);
3027+
ret = ly_path_eval_partial(lypath, ctx_node, NULL, 0, NULL, match);
30283028

30293029
cleanup:
30303030
lyxp_expr_free(LYD_CTX(ctx_node), expr);

src/tree_data.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,6 +1468,7 @@ LIBYANG_API_DECL LY_ERR lyd_new_attr2(struct lyd_node *parent, const char *modul
14681468
#define LYD_NEW_PATH_CANON_VALUE 0x10 /**< Interpret the provided leaf/leaf-list @p value as being in the canonical
14691469
(or JSON if no defined) ::LY_VALUE_CANON format. If it is not, it may lead
14701470
to unexpected behavior. */
1471+
#define LYD_NEW_PATH_WITH_OPAQ 0x20 /**< Consider opaque nodes normally when searching for existing nodes. */
14711472

14721473
/** @} pathoptions */
14731474

src/tree_data_new.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ lyd_new_path_(struct lyd_node *parent, const struct ly_ctx *ctx, const struct ly
15431543

15441544
/* try to find any existing nodes in the path */
15451545
if (parent) {
1546-
r = ly_path_eval_partial(p, parent, NULL, &path_idx, &node);
1546+
r = ly_path_eval_partial(p, parent, NULL, options & LYD_NEW_PATH_WITH_OPAQ, &path_idx, &node);
15471547
if (r == LY_SUCCESS) {
15481548
if (orig_count == LY_ARRAY_COUNT(p)) {
15491549
/* the node exists, are we supposed to update it or is it just a default? */

0 commit comments

Comments
 (0)