C-API: Exposed diff function
Test: double leaf validate test
This commit is contained in:
parent
d358387d39
commit
fcf9a8b0b0
8 changed files with 115 additions and 89 deletions
|
|
@ -733,82 +733,6 @@ cli_validate(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
/*! Compare two dbs using XML. Write to file and run diff
|
||||
*/
|
||||
static int
|
||||
compare_xmls(cxobj *xc1,
|
||||
cxobj *xc2,
|
||||
enum format_enum format)
|
||||
{
|
||||
int fd;
|
||||
FILE *f;
|
||||
char filename1[MAXPATHLEN];
|
||||
char filename2[MAXPATHLEN];
|
||||
int retval = -1;
|
||||
cbuf *cb = NULL;
|
||||
|
||||
snprintf(filename1, sizeof(filename1), "/tmp/cliconXXXXXX");
|
||||
snprintf(filename2, sizeof(filename2), "/tmp/cliconXXXXXX");
|
||||
if ((fd = mkstemp(filename1)) < 0){
|
||||
clicon_err(OE_UNDEF, errno, "tmpfile");
|
||||
goto done;
|
||||
}
|
||||
if ((f = fdopen(fd, "w")) == NULL)
|
||||
goto done;
|
||||
switch(format){
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(f, xc1, 0, cligen_output, 1, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_XML:
|
||||
default:
|
||||
if (clixon_xml2file(f, xc1, 0, 1, cligen_output, 1, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
fclose(f);
|
||||
close(fd);
|
||||
|
||||
if ((fd = mkstemp(filename2)) < 0){
|
||||
clicon_err(OE_UNDEF, errno, "mkstemp: %s", strerror(errno));
|
||||
goto done;
|
||||
}
|
||||
if ((f = fdopen(fd, "w")) == NULL)
|
||||
goto done;
|
||||
|
||||
switch(format){
|
||||
case FORMAT_TEXT:
|
||||
if (clixon_txt2file(f, xc2, 0, cligen_output, 1, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_XML:
|
||||
default:
|
||||
if (clixon_xml2file(f, xc2, 0, 1, cligen_output, 1, 1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
close(fd);
|
||||
|
||||
if ((cb = cbuf_new()) == NULL){
|
||||
clicon_err(OE_CFG, errno, "cbuf_new");
|
||||
goto done;
|
||||
}
|
||||
cprintf(cb, "diff -dU 1 %s %s | grep -v @@ | sed 1,2d",
|
||||
filename1, filename2);
|
||||
if (system(cbuf_get(cb)) < 0)
|
||||
goto done;
|
||||
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
unlink(filename1);
|
||||
unlink(filename2);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/*! Compare two dbs using XML. Write to file and run diff
|
||||
* @param[in] h Clicon handle
|
||||
* @param[in] cvv
|
||||
|
|
@ -845,7 +769,7 @@ compare_dbs(clicon_handle h,
|
|||
clixon_netconf_error(xerr, "Get configuration", NULL);
|
||||
goto done;
|
||||
}
|
||||
if (compare_xmls(xc1, xc2, format) < 0) /* astext? */
|
||||
if (clixon_compare_xmls(xc1, xc2, format, cligen_output) < 0) /* astext? */
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue