@@ -774,12 +774,12 @@ lyd_insert_child(struct lyd_node *parent, struct lyd_node *node)
774774 }
775775
776776 if (node -> parent || node -> prev -> next ) {
777- lyd_unlink_tree (node );
777+ lyd_unlink (node );
778778 }
779779
780780 while (node ) {
781781 iter = node -> next ;
782- lyd_unlink_tree (node );
782+ lyd_unlink (node );
783783 lyd_insert_node (parent , NULL , node , 0 );
784784 node = iter ;
785785 }
@@ -801,7 +801,7 @@ lyplg_ext_insert(struct lyd_node *parent, struct lyd_node *first)
801801
802802 while (first ) {
803803 iter = first -> next ;
804- lyd_unlink_tree (first );
804+ lyd_unlink (first );
805805 lyd_insert_node (parent , NULL , first , 1 );
806806 first = iter ;
807807 }
@@ -825,7 +825,7 @@ lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_n
825825 }
826826
827827 if (node -> parent || node -> prev -> next ) {
828- lyd_unlink_tree (node );
828+ lyd_unlink (node );
829829 }
830830
831831 while (node ) {
@@ -835,7 +835,7 @@ lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_n
835835 }
836836
837837 iter = node -> next ;
838- lyd_unlink_tree (node );
838+ lyd_unlink (node );
839839 lyd_insert_node (NULL , & sibling , node , 0 );
840840 node = iter ;
841841 }
@@ -868,7 +868,7 @@ lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node)
868868 return LY_EINVAL ;
869869 }
870870
871- lyd_unlink_tree (node );
871+ lyd_unlink (node );
872872 lyd_insert_before_node (sibling , node );
873873 lyd_insert_hash (node );
874874
@@ -892,26 +892,15 @@ lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node)
892892 return LY_EINVAL ;
893893 }
894894
895- lyd_unlink_tree (node );
895+ lyd_unlink (node );
896896 lyd_insert_after_node (sibling , node );
897897 lyd_insert_hash (node );
898898
899899 return LY_SUCCESS ;
900900}
901901
902- LIBYANG_API_DEF void
903- lyd_unlink_siblings (struct lyd_node * node )
904- {
905- struct lyd_node * next , * elem , * first = NULL ;
906-
907- LY_LIST_FOR_SAFE (node , next , elem ) {
908- lyd_unlink_tree (elem );
909- lyd_insert_node (NULL , & first , elem , 1 );
910- }
911- }
912-
913- LIBYANG_API_DEF void
914- lyd_unlink_tree (struct lyd_node * node )
902+ void
903+ lyd_unlink (struct lyd_node * node )
915904{
916905 struct lyd_node * iter ;
917906
@@ -959,6 +948,35 @@ lyd_unlink_tree(struct lyd_node *node)
959948 node -> prev = node ;
960949}
961950
951+ LIBYANG_API_DEF void
952+ lyd_unlink_siblings (struct lyd_node * node )
953+ {
954+ struct lyd_node * next , * elem , * first = NULL ;
955+
956+ LY_LIST_FOR_SAFE (node , next , elem ) {
957+ if (lysc_is_key (elem -> schema ) && elem -> parent ) {
958+ LOGERR (LYD_CTX (elem ), LY_EINVAL , "Cannot unlink a list key \"%s\", unlink the list instance instead." ,
959+ LYD_NAME (elem ));
960+ return ;
961+ }
962+
963+ lyd_unlink (elem );
964+ lyd_insert_node (NULL , & first , elem , 1 );
965+ }
966+ }
967+
968+ LIBYANG_API_DEF void
969+ lyd_unlink_tree (struct lyd_node * node )
970+ {
971+ if (node && lysc_is_key (node -> schema ) && node -> parent ) {
972+ LOGERR (LYD_CTX (node ), LY_EINVAL , "Cannot unlink a list key \"%s\", unlink the list instance instead." ,
973+ LYD_NAME (node ));
974+ return ;
975+ }
976+
977+ lyd_unlink (node );
978+ }
979+
962980void
963981lyd_insert_meta (struct lyd_node * parent , struct lyd_meta * meta , ly_bool clear_dflt )
964982{
@@ -2179,7 +2197,7 @@ lyd_merge_sibling_r(struct lyd_node **first_trg, struct lyd_node *parent_trg, co
21792197 /* node not found, merge it */
21802198 if (options & LYD_MERGE_DESTRUCT ) {
21812199 dup_src = (struct lyd_node * )sibling_src ;
2182- lyd_unlink_tree (dup_src );
2200+ lyd_unlink (dup_src );
21832201 /* spend it */
21842202 * sibling_src_p = NULL ;
21852203 } else {
0 commit comments