Skip to content

Commit 99bfd40

Browse files
committed
schema compile UPDATE fix disabled list unique nodes
... instead of producing an error. The error could be avoided for nodes diabled by a deviation but not when disabled by a feature. Refs #2217
1 parent 2a01181 commit 99bfd40

File tree

2 files changed

+72
-7
lines changed

2 files changed

+72
-7
lines changed

src/schema_compile.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,8 +1218,9 @@ static LY_ERR
12181218
lys_compile_unres_check_disabled(const struct lysc_node *node)
12191219
{
12201220
const struct lysc_node *parent;
1221-
const struct lysc_node_list *slist;
1221+
struct lysc_node_list *slist;
12221222
LY_ARRAY_COUNT_TYPE u, v;
1223+
int found;
12231224

12241225
if (node->flags & LYS_KEY) {
12251226
LOG_LOCSET(node, NULL);
@@ -1233,16 +1234,42 @@ lys_compile_unres_check_disabled(const struct lysc_node *node)
12331234
continue;
12341235
}
12351236

1236-
/* check list uniques */
1237+
/* check and fix list uniques */
12371238
slist = (struct lysc_node_list *)parent;
1239+
found = 0;
12381240
LY_ARRAY_FOR(slist->uniques, u) {
12391241
LY_ARRAY_FOR(slist->uniques[u], v) {
12401242
if (slist->uniques[u][v] == (struct lysc_node_leaf *)node) {
1241-
LOG_LOCSET(node, NULL);
1242-
LOGVAL(node->module->ctx, LYVE_REFERENCE, "Disabled node \"%s\" is referenced as unique in the list \"%s\".",
1243-
node->name, slist->name);
1244-
LOG_LOCBACK(1, 0);
1245-
return LY_EVALID;
1243+
found = 1;
1244+
break;
1245+
}
1246+
}
1247+
1248+
if (found) {
1249+
break;
1250+
}
1251+
}
1252+
1253+
if (found) {
1254+
if (LY_ARRAY_COUNT(slist->uniques[u]) > 1) {
1255+
/* remove the item */
1256+
if (v < LY_ARRAY_COUNT(slist->uniques[u]) - 1) {
1257+
memmove(&slist->uniques[u][v], &slist->uniques[u][v + 1],
1258+
(LY_ARRAY_COUNT(slist->uniques[u]) - v - 1) * sizeof slist->uniques[u][v]);
1259+
}
1260+
LY_ARRAY_DECREMENT(slist->uniques[u]);
1261+
} else {
1262+
/* remove the whole unique array */
1263+
LY_ARRAY_FREE(slist->uniques[u]);
1264+
if (LY_ARRAY_COUNT(slist->uniques) > 1) {
1265+
if (u < LY_ARRAY_COUNT(slist->uniques) - 1) {
1266+
memmove(&slist->uniques[u], &slist->uniques[u + 1],
1267+
(LY_ARRAY_COUNT(slist->uniques) - u - 1) * sizeof slist->uniques[u]);
1268+
}
1269+
LY_ARRAY_DECREMENT(slist->uniques);
1270+
} else {
1271+
LY_ARRAY_FREE(slist->uniques);
1272+
slist->uniques = NULL;
12461273
}
12471274
}
12481275
}

tests/utests/schema/test_tree_schema_compile.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4031,6 +4031,43 @@ test_must(void **state)
40314031
"with context node \"/b:laa-config\".", NULL, 0);
40324032
}
40334033

4034+
static void
4035+
test_unique_disabled(void **state)
4036+
{
4037+
assert_int_equal(LY_SUCCESS, lys_parse_mem(UTEST_LYCTX,
4038+
"module list-unique {"
4039+
" namespace urn:lu;"
4040+
" prefix lu;"
4041+
" feature f;"
4042+
" list l {"
4043+
" key \"k\";"
4044+
" unique \"v\";"
4045+
" leaf k {"
4046+
" type string;"
4047+
" }"
4048+
" leaf v {"
4049+
" if-feature f;"
4050+
" type string;"
4051+
" }"
4052+
" }"
4053+
" list l2 {"
4054+
" key \"k\";"
4055+
" unique \"v1 v2\";"
4056+
" leaf k {"
4057+
" type string;"
4058+
" }"
4059+
" leaf v1 {"
4060+
" if-feature f;"
4061+
" type string;"
4062+
" }"
4063+
" leaf v2 {"
4064+
" type string;"
4065+
" }"
4066+
" }"
4067+
"}",
4068+
LYS_IN_YANG, NULL));
4069+
}
4070+
40344071
int
40354072
main(void)
40364073
{
@@ -4066,6 +4103,7 @@ main(void)
40664103
UTEST(test_deviation, setup),
40674104
UTEST(test_when, setup),
40684105
UTEST(test_must, setup),
4106+
UTEST(test_unique_disabled, setup),
40694107
};
40704108

40714109
return cmocka_run_group_tests(tests, NULL, NULL);

0 commit comments

Comments
 (0)