Fixed: [Problem deleting non-last list element if ordered-by user](https://github.com/clicon/clixon/issues/475)
This commit is contained in:
parent
cb3e74971d
commit
04a548ad78
6 changed files with 389 additions and 25 deletions
|
|
@ -652,7 +652,7 @@ _xml_parse(const char *str,
|
|||
if (xml_sort_recurse(xt) < 0)
|
||||
goto done;
|
||||
retval = 1;
|
||||
done:
|
||||
done:
|
||||
clixon_xml_parsel_exit(&xy);
|
||||
if (xy.xy_parse_string != NULL)
|
||||
free(xy.xy_parse_string);
|
||||
|
|
@ -955,6 +955,67 @@ xml_diff_context(cbuf *cb,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Handle order-by user(leaf)list for xml_diff2cbuf
|
||||
*
|
||||
* @param[out] cb CLIgen buffer
|
||||
* @param[in] x0 First XML tree
|
||||
* @param[in] x1 Second XML tree
|
||||
* @param[in] x0c Start of sublist in first XML tree
|
||||
* @param[in] x1c Start of sublist in second XML tree
|
||||
* @param[in] yc Yang of x0c/x1c
|
||||
* @param[in] level How many spaces to insert before each line
|
||||
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
|
||||
* @retval 0 Ok
|
||||
* @retval -1 Error
|
||||
* @see xml_diff_ordered_by_user
|
||||
* @see text_diff2cbuf_ordered_by_user
|
||||
*/
|
||||
static int
|
||||
xml_diff2cbuf_ordered_by_user(cbuf *cb,
|
||||
cxobj *x0,
|
||||
cxobj *x1,
|
||||
cxobj *x0c,
|
||||
cxobj *x1c,
|
||||
yang_stmt *yc,
|
||||
int level,
|
||||
int skiptop)
|
||||
{
|
||||
int retval = 1;
|
||||
cxobj *xi;
|
||||
cxobj *xj;
|
||||
|
||||
xj = x1c;
|
||||
do {
|
||||
xml_flag_set(xj, XML_FLAG_ADD);
|
||||
} while ((xj = xml_child_each(x1, xj, CX_ELMNT)) != NULL &&
|
||||
xml_spec(xj) == yc);
|
||||
/* If in both sets, unmark add/del */
|
||||
xi = x0c;
|
||||
do {
|
||||
xml_flag_set(xi, XML_FLAG_DEL);
|
||||
xj = x1c;
|
||||
do {
|
||||
if (xml_flag(xj, XML_FLAG_ADD) &&
|
||||
xml_cmp(xi, xj, 0, 0, NULL) == 0){
|
||||
/* Unmark node in x0 and x1 */
|
||||
xml_flag_reset(xi, XML_FLAG_DEL);
|
||||
xml_flag_reset(xj, XML_FLAG_ADD);
|
||||
if (xml_diff2cbuf(cb, xi, xj, level+1, 0) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ((xj = xml_child_each(x1, xj, CX_ELMNT)) != NULL &&
|
||||
xml_spec(xj) == yc);
|
||||
}
|
||||
while ((xi = xml_child_each(x0, xi, CX_ELMNT)) != NULL &&
|
||||
xml_spec(xi) == yc);
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Print XML diff of two cxobj trees into a cbuf
|
||||
*
|
||||
* YANG dependent
|
||||
|
|
@ -974,6 +1035,7 @@ xml_diff_context(cbuf *cb,
|
|||
* @endcode
|
||||
* @see xml_diff which returns diff sets
|
||||
* @see clixon_compare_xmls which uses files and is independent of YANG
|
||||
* @see text_diff2cbuf
|
||||
*/
|
||||
int
|
||||
xml_diff2cbuf(cbuf *cb,
|
||||
|
|
@ -995,6 +1057,8 @@ xml_diff2cbuf(cbuf *cb,
|
|||
int eq;
|
||||
int nr=0;
|
||||
int level1;
|
||||
cxobj *xi;
|
||||
cxobj *xj;
|
||||
|
||||
level1 = level*PRETTYPRINT_INDENT;
|
||||
y0 = xml_spec(x0);
|
||||
|
|
@ -1030,7 +1094,52 @@ xml_diff2cbuf(cbuf *cb,
|
|||
}
|
||||
/* Both x0c and x1c exists, check if they are yang-equal. */
|
||||
eq = xml_cmp(x0c, x1c, 0, 0, NULL);
|
||||
if (eq < 0){
|
||||
yc0 = xml_spec(x0c);
|
||||
yc1 = xml_spec(x1c);
|
||||
if (eq && yc0 && yc1 && yang_find(yc0, Y_ORDERED_BY, "user")){
|
||||
if (xml_diff2cbuf_ordered_by_user(cb, x0, x1, x0c, x1c, yc0,
|
||||
level, skiptop) < 0)
|
||||
goto done;
|
||||
/* Add all in x0 marked as DELETE in x0vec
|
||||
* Flags can remain: XXX should apply to all
|
||||
*/
|
||||
xi = x0c;
|
||||
do {
|
||||
if (xml_flag(xi, XML_FLAG_DEL)){
|
||||
xml_flag_reset(xi, XML_FLAG_DEL);
|
||||
if (nr==0 && skiptop==0){
|
||||
xml_diff_context(cb, x0, level1);
|
||||
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
|
||||
nr++;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, xi, level+1, 1, "-", -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
while ((xi = xml_child_each(x0, xi, CX_ELMNT)) != NULL &&
|
||||
xml_spec(xi) == yc0);
|
||||
x0c = xi;
|
||||
|
||||
/* Add all in x1 marked as ADD in x1vec */
|
||||
xj = x1c;
|
||||
do {
|
||||
if (xml_flag(xj, XML_FLAG_ADD)){
|
||||
xml_flag_reset(xj, XML_FLAG_ADD);
|
||||
if (nr==0 && skiptop==0){
|
||||
xml_diff_context(cb, x1, level1);
|
||||
xml_diff_keys(cb, x1, y0, (level+1)*PRETTYPRINT_INDENT);
|
||||
nr++;
|
||||
}
|
||||
if (clixon_xml2cbuf(cb, xj, level+1, 1, "+", -1, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
while ((xj = xml_child_each(x1, xj, CX_ELMNT)) != NULL &&
|
||||
xml_spec(xj) == yc1);
|
||||
x1c = xj;
|
||||
continue;
|
||||
}
|
||||
else if (eq < 0){
|
||||
if (nr==0 && skiptop==0){
|
||||
xml_diff_context(cb, x0, level1);
|
||||
xml_diff_keys(cb, x0, y0, (level+1)*PRETTYPRINT_INDENT);
|
||||
|
|
@ -1056,8 +1165,6 @@ xml_diff2cbuf(cbuf *cb,
|
|||
/* xml-spec NULL could happen with anydata children for example,
|
||||
* if so, continute compare children but without yang
|
||||
*/
|
||||
yc0 = xml_spec(x0c);
|
||||
yc1 = xml_spec(x1c);
|
||||
if (yc0 && yc1 && yc0 != yc1){ /* choice */
|
||||
if (nr==0 && skiptop==0){
|
||||
xml_diff_context(cb, x0, level1);
|
||||
|
|
@ -1145,6 +1252,7 @@ xml_diff2cbuf(cbuf *cb,
|
|||
* @endcode
|
||||
* @see xml_diff which returns diff sets
|
||||
* @see clixon_compare_xmls which uses files and is independent of YANG
|
||||
* @see clixon_text_diff2cbuf
|
||||
*/
|
||||
int
|
||||
clixon_xml_diff2cbuf(cbuf *cb,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue