tree data UPDATE restoring op data tree

In case there are sibling nodes of an operation,
restore them back correctly after the validation.
diff --git a/src/tree_data.c b/src/tree_data.c
index eee87c8..60a17b5 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -483,15 +483,7 @@
     return match;
 }
 
-/**
- * @brief Insert node after a sibling.
- *
- * Handles inserting into NP containers and key-less lists.
- *
- * @param[in] sibling Sibling to insert after.
- * @param[in] node Node to insert.
- */
-static void
+void
 lyd_insert_after_node(struct lyd_node *sibling, struct lyd_node *node)
 {
     struct lyd_node_inner *par;
@@ -523,15 +515,7 @@
     }
 }
 
-/**
- * @brief Insert node before a sibling.
- *
- * Handles inserting into NP containers and key-less lists.
- *
- * @param[in] sibling Sibling to insert before.
- * @param[in] node Node to insert.
- */
-static void
+void
 lyd_insert_before_node(struct lyd_node *sibling, struct lyd_node *node)
 {
     struct lyd_node_inner *par;
diff --git a/src/tree_data_internal.h b/src/tree_data_internal.h
index 408b3db..8450580 100644
--- a/src/tree_data_internal.h
+++ b/src/tree_data_internal.h
@@ -364,6 +364,26 @@
 struct lyd_node *lyd_insert_get_next_anchor(const struct lyd_node *first_sibling, const struct lyd_node *new_node);
 
 /**
+ * @brief Insert node after a sibling.
+ *
+ * Handles inserting into NP containers and key-less lists.
+ *
+ * @param[in] sibling Sibling to insert after.
+ * @param[in] node Node to insert.
+ */
+void lyd_insert_after_node(struct lyd_node *sibling, struct lyd_node *node);
+
+/**
+ * @brief Insert node before a sibling.
+ *
+ * Handles inserting into NP containers and key-less lists.
+ *
+ * @param[in] sibling Sibling to insert before.
+ * @param[in] node Node to insert.
+ */
+void lyd_insert_before_node(struct lyd_node *sibling, struct lyd_node *node);
+
+/**
  * @brief Insert a node into parent/siblings. Order and hashes are fully handled.
  *
  * @param[in] parent Parent to insert into, NULL for top-level sibling.
diff --git a/src/validation.c b/src/validation.c
index 3b0b51b..8d2868a 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -1753,7 +1753,10 @@
 
     /* merge op_tree into dep_tree */
     lyd_val_op_merge_find(op_tree, op_node, dep_tree, &op_subtree, &tree_sibling, &tree_parent);
+    op_sibling_before = op_subtree->prev->next ? op_subtree->prev : NULL;
+    op_sibling_after = op_subtree->next;
     op_parent = lyd_parent(op_subtree);
+
     lyd_unlink_tree(op_subtree);
     lyd_insert_node(tree_parent, &tree_sibling, op_subtree, 0);
     if (!dep_tree) {
@@ -1798,9 +1801,14 @@
 
 cleanup:
     LOG_LOCBACK(0, 1, 0, 0);
+
     /* restore operation tree */
     lyd_unlink_tree(op_subtree);
-    if (op_parent) {
+    if (op_sibling_before) {
+        lyd_insert_after_node(op_sibling_before, op_subtree);
+    } else if (op_sibling_after) {
+        lyd_insert_before_node(op_sibling_after, op_subtree);
+    } else if (op_parent) {
         lyd_insert_node(op_parent, NULL, op_subtree, 0);
     }