From: Igor Ryzhov Date: Mon, 22 Apr 2024 13:49:03 +0000 (+0300) Subject: lib: fix style and add more comments to NB code X-Git-Tag: base_10.1~101^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=cb88ce132a68506a1f738accea3c715322722457;p=mirror%2Ffrr.git lib: fix style and add more comments to NB code Signed-off-by: Igor Ryzhov --- diff --git a/lib/northbound.c b/lib/northbound.c index 57068cc4e0..0bc79d0277 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -932,14 +932,22 @@ static int nb_candidate_edit_tree_add(struct nb_config *candidate, /* if replace failed, restore the original node */ if (existing) { if (root) { + /* Restoring the whole config. */ candidate->dnode = existing; + } else if (ex_parent) { + /* + * Restoring a nested node. Insert it as a + * child. + */ + lyd_insert_child(ex_parent, existing); } else { - if (ex_parent) - lyd_insert_child(ex_parent, existing); - else - lyd_insert_sibling(candidate->dnode, - existing, - &candidate->dnode); + /* + * Restoring a top-level node. Insert it as a + * sibling to candidate->dnode to make sure + * the linkage is correct. + */ + lyd_insert_sibling(candidate->dnode, existing, + &candidate->dnode); } } yang_print_errors(ly_native_ctx, errmsg, errmsg_len);