System-only config: Source of truth
Candidate, fix system-only in cache when locked or modified, re-read otherwise Remove system-only from cache after commit
This commit is contained in:
parent
cfa4803e0f
commit
313a2caadd
16 changed files with 189 additions and 78 deletions
|
|
@ -428,6 +428,7 @@ xmldb_unlock(clixon_handle h,
|
|||
de->de_id = 0;
|
||||
memset(&de->de_tv, 0, sizeof(struct timeval));
|
||||
clicon_db_elmnt_set(h, db, de);
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -472,7 +473,7 @@ xmldb_unlock_all(clixon_handle h,
|
|||
*
|
||||
* @param[in] h Clixon handle
|
||||
* @param[in] db Database
|
||||
* @retval >0 Session id of locker
|
||||
* @retval >0 Session id of locker
|
||||
* @retval 0 Not locked
|
||||
* @retval -1 Error
|
||||
*/
|
||||
|
|
@ -562,6 +563,9 @@ xmldb_clear(clixon_handle h,
|
|||
xml_free(xt);
|
||||
de->de_xml = NULL;
|
||||
}
|
||||
de->de_modified = 0;
|
||||
de->de_id = 0;
|
||||
memset(&de->de_tv, 0, sizeof(struct timeval));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -572,8 +576,8 @@ xmldb_clear(clixon_handle h,
|
|||
* @param[in] db Database
|
||||
* @retval 0 OK
|
||||
* @retval -1 Error
|
||||
|
||||
* @note Datastore is not actually deleted so that a backend after dropping priviliges can re-create it
|
||||
* @note Datastores / dirs are not actually deleted so that a backend after dropping priviliges
|
||||
* can re-create them
|
||||
*/
|
||||
int
|
||||
xmldb_delete(clixon_handle h,
|
||||
|
|
@ -612,17 +616,11 @@ xmldb_delete(clixon_handle h,
|
|||
for (i = 0; i < ndp; i++){
|
||||
cbuf_reset(cb);
|
||||
cprintf(cb, "%s/%s", subdir, dp[i].d_name);
|
||||
if (unlink(cbuf_get(cb)) < 0){
|
||||
clixon_err(OE_DB, errno, "unlink(%s)", cbuf_get(cb));
|
||||
if (truncate(cbuf_get(cb), 0) < 0){
|
||||
clixon_err(OE_DB, errno, "truncate %s", filename);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (rmdir(subdir) < 0){
|
||||
#if 0 /* Ignore this for now, there are some cornercases where this is problamatic, see confirmed-commit */
|
||||
clixon_err(OE_DB, errno, "rmdir(%s)", subdir);
|
||||
goto done;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
retval = 0;
|
||||
|
|
|
|||
|
|
@ -886,10 +886,13 @@ xmldb_get_cache(clixon_handle h,
|
|||
if (xml_apply(x1t, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, (void*)(XML_FLAG_MARK|XML_FLAG_CHANGE)) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_SYSTEM_ONLY_CONFIG") &&
|
||||
(strcmp(db, "candidate") != 0)) {
|
||||
if (xmldb_system_only_config(h, xpath?xpath:"/", nsc, &x1t) < 0)
|
||||
goto done;
|
||||
/* Unless a modified/locked candidate, add system-only-config data */
|
||||
if (strcmp(db, "candidate") != 0 ||
|
||||
(xmldb_modified_get(h, db) == 0 &&
|
||||
xmldb_islocked(h, db) == 0)){
|
||||
if (clicon_option_bool(h, "CLICON_XMLDB_SYSTEM_ONLY_CONFIG"))
|
||||
if (xmldb_system_only_config(h, xpath?xpath:"/", nsc, &x1t) < 0)
|
||||
goto done;
|
||||
}
|
||||
/* If empty NACM config, then disable NACM if loaded
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1239,7 +1239,15 @@ text_modify_top(clixon_handle h,
|
|||
/* Special case top-level replace */
|
||||
else if (op == OP_REPLACE || op == OP_DELETE){
|
||||
if (createstr != NULL){
|
||||
if (xml_child_nr_type(x0t, CX_ELMNT)) /* base tree not empty */
|
||||
x0c = NULL;
|
||||
/* Specialization of xml_default_nopresence for skiptop and mode=0 */
|
||||
while ((x0c = xml_child_each(x0t, x0c, CX_ELMNT)) != NULL) {
|
||||
if ((ret = xml_default_nopresence(x0c, 0, 0)) < 0)
|
||||
goto done;
|
||||
if (ret == 0)
|
||||
break;
|
||||
}
|
||||
if (x0c != NULL)
|
||||
clicon_data_set(h, "objectexisted", "true");
|
||||
else
|
||||
clicon_data_set(h, "objectexisted", "false");
|
||||
|
|
@ -1421,6 +1429,12 @@ xmldb_put(clixon_handle h,
|
|||
goto done;
|
||||
if (ret == 0)
|
||||
goto fail;
|
||||
/* Add default global values (see also xmldb_populate) */
|
||||
if (xml_global_defaults(h, x0, nsc, "/", yspec, 0) < 0)
|
||||
goto done;
|
||||
/* Add default recursive values */
|
||||
if (xml_default_recurse(x0, 0, 0) < 0)
|
||||
goto done;
|
||||
}
|
||||
if (strcmp(xml_name(x0), DATASTORE_TOP_SYMBOL) !=0 ||
|
||||
xml_flag(x0, XML_FLAG_TOP) == 0){
|
||||
|
|
@ -1461,7 +1475,7 @@ xmldb_put(clixon_handle h,
|
|||
*/
|
||||
if (xml_default_nopresence(x0, 3, XML_FLAG_ADD|XML_FLAG_DEL) < 0)
|
||||
goto done;
|
||||
/* Complete defaults in incoming x1
|
||||
/* Complete defaults
|
||||
*/
|
||||
if (xml_global_defaults(h, x0, nsc, "/", yspec, 0) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue