Skip to content

Commit c35d2a7

Browse files
committed
resolve BUGFIX resolving leafrefs must be done after when
Fixes sysrepo/sysrepo#830
1 parent ce25fa2 commit c35d2a7

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

src/resolve.c

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7866,7 +7866,7 @@ unres_data_add(struct unres_data *unres, struct lyd_node *node, enum UNRES_ITEM
78667866
int
78677867
resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options)
78687868
{
7869-
uint32_t i, j, first = 1, resolved = 0, del_items = 0, when_stmt = 0;
7869+
uint32_t i, j, first, resolved, del_items, stmt_count;
78707870
int rc, progress, ignore_fail;
78717871
struct lyd_node *parent;
78727872

@@ -7889,16 +7889,20 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
78897889
ly_vlog_hide(1);
78907890

78917891
/* when-stmt first */
7892+
first = 1;
7893+
stmt_count = 0;
7894+
resolved = 0;
7895+
del_items = 0;
78927896
do {
78937897
ly_err_clean(1);
78947898
progress = 0;
78957899
for (i = 0; i < unres->count; i++) {
7896-
if (unres->type[i] != UNRES_WHEN && unres->type[i] != UNRES_LEAFREF) {
7900+
if (unres->type[i] != UNRES_WHEN) {
78977901
continue;
78987902
}
78997903
if (first) {
79007904
/* count when-stmt nodes in unres list */
7901-
when_stmt++;
7905+
stmt_count++;
79027906
}
79037907

79047908
/* resolve when condition only when all parent when conditions are already resolved */
@@ -7989,10 +7993,10 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
79897993
} /* else forward reference */
79907994
}
79917995
first = 0;
7992-
} while (progress && resolved < when_stmt);
7996+
} while (progress && resolved < stmt_count);
79937997

79947998
/* do we have some unresolved when-stmt? */
7995-
if (when_stmt > resolved) {
7999+
if (stmt_count > resolved) {
79968000
ly_vlog_hide(0);
79978001
ly_err_repeat();
79988002
return -1;
@@ -8014,6 +8018,45 @@ resolve_unres_data(struct unres_data *unres, struct lyd_node **root, int options
80148018
unres->type[i] = UNRES_RESOLVED;
80158019
del_items--;
80168020
}
8021+
8022+
/* now leafrefs */
8023+
first = 1;
8024+
stmt_count = 0;
8025+
resolved = 0;
8026+
do {
8027+
progress = 0;
8028+
for (i = 0; i < unres->count; i++) {
8029+
if (unres->type[i] != UNRES_LEAFREF) {
8030+
continue;
8031+
}
8032+
if (first) {
8033+
/* count leafref nodes in unres list */
8034+
stmt_count++;
8035+
}
8036+
8037+
rc = resolve_unres_data_item(unres->node[i], unres->type[i], ignore_fail);
8038+
if (!rc) {
8039+
unres->type[i] = UNRES_RESOLVED;
8040+
ly_err_clean(1);
8041+
resolved++;
8042+
progress = 1;
8043+
} else if (rc == -1) {
8044+
ly_vlog_hide(0);
8045+
/* print only this last error */
8046+
resolve_unres_data_item(unres->node[i], unres->type[i], ignore_fail);
8047+
return -1;
8048+
} /* else forward reference */
8049+
}
8050+
first = 0;
8051+
} while (progress && resolved < stmt_count);
8052+
8053+
/* do we have some unresolved leafrefs? */
8054+
if (stmt_count > resolved) {
8055+
ly_vlog_hide(0);
8056+
ly_err_repeat();
8057+
return -1;
8058+
}
8059+
80178060
ly_vlog_hide(0);
80188061

80198062
/* rest */

0 commit comments

Comments
 (0)