diff --git a/lib/src/clixon_datastore_write.c b/lib/src/clixon_datastore_write.c index fa456d05e..e41d85674 100644 --- a/lib/src/clixon_datastore_write.c +++ b/lib/src/clixon_datastore_write.c @@ -581,15 +581,14 @@ text_modify(clixon_handle h, } case OP_REPLACE: /* fall thru */ case OP_MERGE: - /* If default flag, clear it */ - if (x0 && xml_flag(x0, XML_FLAG_DEFAULT)) - xml_flag_reset(x0, XML_FLAG_DEFAULT); if (!(op == OP_MERGE && (instr==NULL))) { /* Remove existing, also applies to merge in the special case * of ordered-by user and (changed) insert attribute. */ if (!permit && xnacm){ - if ((ret = nacm_datanode_write(h, x1, x1t, x0?NACM_UPDATE:NACM_CREATE, username, xnacm, cbret)) < 0) + if ((ret = nacm_datanode_write(h, x1, x1t, + (x0 == NULL || xml_default_nopresence(x0, 0, 0))?NACM_CREATE:NACM_UPDATE, + username, xnacm, cbret)) < 0) goto done; if (ret == 0) goto fail; @@ -603,6 +602,9 @@ text_modify(clixon_handle h, x0 = NULL; } } /* OP_MERGE & insert */ + /* If default flag, clear it, since replaced */ + if (x0 && xml_flag(x0, XML_FLAG_DEFAULT)) + xml_flag_reset(x0, XML_FLAG_DEFAULT); case OP_NONE: /* fall thru */ if (x0==NULL){ if ((op != OP_NONE) && !permit && xnacm){ @@ -718,7 +720,6 @@ text_modify(clixon_handle h, /* Purge if x1 value is NULL(match-all) or both values are equal */ if ((x1bstr == NULL) || ((x0bstr=xml_body(x0)) != NULL && strcmp(x0bstr, x1bstr)==0)){ - if (xml_purge(x0) < 0) goto done; xml_flag_set(x0p, XML_FLAG_DEL); diff --git a/test/test_nacm_module_write.sh b/test/test_nacm_module_write.sh index 7079b2559..35dd6fa12 100755 --- a/test/test_nacm_module_write.sh +++ b/test/test_nacm_module_write.sh @@ -66,6 +66,12 @@ module nacm-example{ import ietf-netconf-acm { prefix nacm; } + container global { + leaf enabled { + type boolean; + default false; + } + } leaf x{ type int32; description "something to edit"; @@ -283,6 +289,9 @@ expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/y new "default delete list deny" expectpart "$(curl -u wilma:bar $CURLOPTS -X DELETE $RCPROTO://localhost/restconf/data/clixon-example:table/parameter=key42)" 0 "HTTP/$HVER 403" '{"ietf-restconf:errors":{"error":{"error-type":"application","error-tag":"access-denied","error-severity":"error","error-message":"default deny"}}' +new "create leaf w default value" +expectpart "$(curl -u wilma:bar $CURLOPTS -X PUT -H "Content-Type: application/yang-data+json" $RCPROTO://localhost/restconf/data/nacm-example:global/enabled -d '{"nacm-example:enabled": true}')" 0 "HTTP/$HVER 201" + if [ $RC -ne 0 ]; then new "Kill restconf daemon" stop_restconf