]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: fix style and add more comments to NB code 15594/head
authorIgor Ryzhov <iryzhov@nfware.com>
Mon, 22 Apr 2024 13:49:03 +0000 (16:49 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Mon, 22 Apr 2024 13:49:03 +0000 (16:49 +0300)
Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
lib/northbound.c

index 57068cc4e050696e6ecde1de5de97620b2017f52..0bc79d02774094ea74dd4cb61b05e9f16edf1a3b 100644 (file)
@@ -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);