@@ -3518,7 +3518,9 @@ sr_delete_item(sr_session_ctx_t *session, const char *path, const sr_edit_option
35183518 const char * op ;
35193519 const struct lysc_node * snode ;
35203520 struct lyd_node * node ;
3521+ struct ly_set * set ;
35213522 uint32_t temp_lo = 0 ;
3523+ uint32_t i ;
35223524 int rc ;
35233525
35243526 SR_CHECK_ARG_APIRET (!session || !path || !SR_IS_STANDARD_DS (session -> ds ) || (!SR_IS_CONVENTIONAL_DS (session -> ds ) &&
@@ -3552,17 +3554,39 @@ sr_delete_item(sr_session_ctx_t *session, const char *path, const sr_edit_option
35523554 }
35533555
35543556 if (session -> ds == SR_DS_OPERATIONAL ) {
3555- /* just delete the selected node */
3556- node = NULL ;
3557- if (session -> dt [session -> ds ].edit -> tree &&
3558- (err_info = sr_lyd_find_path (session -> dt [session -> ds ].edit -> tree , path , 1 , & node ))) {
3557+ if ((err_info = sr_lys_find_path (session -> conn -> ly_ctx , path , NULL , & snode ))) {
3558+ /* invalid path */
35593559 goto cleanup ;
35603560 }
3561- if (node ) {
3562- sr_lyd_free_tree_safe (node , & session -> dt [session -> ds ].edit -> tree );
3563- } else if (opts & SR_EDIT_STRICT ) {
3564- /* not found */
3565- sr_errinfo_new (& err_info , SR_ERR_NOT_FOUND , "Node \"%s\" not found in session push oper data." , path );
3561+ if ((snode -> nodetype & (LYS_LIST | LYS_LEAFLIST )) && (path [strlen (path ) - 1 ] != ']' )) {
3562+ /* purge all the (leaf-)list instances */
3563+ set = NULL ;
3564+ if (session -> dt [session -> ds ].edit -> tree &&
3565+ (err_info = sr_lyd_find_xpath (session -> dt [session -> ds ].edit -> tree , path , & set ))) {
3566+ goto cleanup ;
3567+ }
3568+ if (set -> count ) {
3569+ for (i = 0 ; i < set -> count ; ++ i ) {
3570+ sr_lyd_free_tree_safe (set -> dnodes [i ], & session -> dt [session -> ds ].edit -> tree );
3571+ }
3572+ } else if (opts & SR_EDIT_STRICT ) {
3573+ /* not found */
3574+ sr_errinfo_new (& err_info , SR_ERR_NOT_FOUND , "No nodes \"%s\" found in session push oper data." , path );
3575+ }
3576+ ly_set_free (set , NULL );
3577+ } else {
3578+ /* just delete the selected node */
3579+ node = NULL ;
3580+ if (session -> dt [session -> ds ].edit -> tree &&
3581+ (err_info = sr_lyd_find_path (session -> dt [session -> ds ].edit -> tree , path , 1 , & node ))) {
3582+ goto cleanup ;
3583+ }
3584+ if (node ) {
3585+ sr_lyd_free_tree_safe (node , & session -> dt [session -> ds ].edit -> tree );
3586+ } else if (opts & SR_EDIT_STRICT ) {
3587+ /* not found */
3588+ sr_errinfo_new (& err_info , SR_ERR_NOT_FOUND , "Node \"%s\" not found in session push oper data." , path );
3589+ }
35663590 }
35673591 goto cleanup ;
35683592 }
0 commit comments