From 5911d23efc34fb3c41ace5a95ef2a01b4849ae8a Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Mon, 3 Aug 2020 13:08:43 +0200 Subject: [PATCH] patch quit startup upgrading --- lib/src/clixon_datastore_write.c | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index c57c21af..0559fa05 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -1039,3 +1039,39 @@ xmldb_put(clicon_handle h, retval = 0; goto done; } + +/* Dump a datastore to file including modstate + */ +int +xmldb_dump(clicon_handle h, + FILE *f, + cxobj *xt) +{ + int retval = -1; + cxobj *x; + cxobj *xmodst = NULL; + char *format; + int pretty; + + /* Add modstate first */ + if ((x = clicon_modst_cache_get(h, 1)) != NULL){ + if ((xmodst = xml_dup(x)) == NULL) + goto done; + if (xml_child_insert_pos(xt, xmodst, 0) < 0) + goto done; + } + if ((format = clicon_option_str(h, "CLICON_XMLDB_FORMAT")) == NULL){ + clicon_err(OE_CFG, ENOENT, "No CLICON_XMLDB_FORMAT"); + goto done; + } + pretty = clicon_option_bool(h, "CLICON_XMLDB_PRETTY"); + if (strcmp(format,"json")==0){ + if (xml2json(f, xt, pretty) < 0) + goto done; + } + else if (clicon_xml2file(f, xt, 0, pretty) < 0) + goto done; + retval = 0; + done: + return retval; +}