summaryrefslogtreecommitdiff
path: root/src/config_diff.ml
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2024-03-29 20:10:27 +0100
committerGitHub <noreply@github.com>2024-03-29 20:10:27 +0100
commitf8d6abdf8fa9f33b4730e4ed3834a560e857839b (patch)
treef90528ad2df47376dbf1d72bb182e8a683788eb6 /src/config_diff.ml
parent406158f8557fd6ea88168357be1353fb58012b27 (diff)
parentbe75413eaf4aef85274cc16c2283486799d99d73 (diff)
downloadvyos1x-config-f8d6abdf8fa9f33b4730e4ed3834a560e857839b.tar.gz
vyos1x-config-f8d6abdf8fa9f33b4730e4ed3834a560e857839b.zip
Merge pull request #25 from jestabro/tree-mask
T6180: add ability to apply mask to config tree
Diffstat (limited to 'src/config_diff.ml')
-rw-r--r--src/config_diff.ml29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/config_diff.ml b/src/config_diff.ml
index 35a5b55..3529a5d 100644
--- a/src/config_diff.ml
+++ b/src/config_diff.ml
@@ -390,6 +390,35 @@ let show_diff ?(cmds=false) path left right =
in
strs
+let is_terminal_path node path =
+ try
+ let n = Vytree.get node path in
+ match (Vytree.children_of_node n) with
+ | [] -> true
+ | _ -> false
+ with Vytree.Nonexistent_path -> false
+
+(* mask function; mask applied on right *)
+let mask_func ?recurse:_ (path : string list) (Diff_tree res) (m : change) =
+ match m with
+ | Added -> Diff_tree (res)
+ | Subtracted ->
+ (match path with
+ | [_] -> Diff_tree {res with left = Vytree.delete res.left path}
+ | _ -> if not (is_terminal_path res.right (list_but_last path)) then
+ Diff_tree {res with left = Vytree.delete res.left path}
+ else Diff_tree (res))
+ | Unchanged -> Diff_tree (res)
+ | Updated _ -> Diff_tree (res)
+
+(* call recursive diff with mask_func; mask applied on right *)
+let mask_tree left right =
+ let trees = make_diff_trees left right in
+ let d = diff [] mask_func trees (Option.some left, Option.some right)
+ in
+ let res = eval_result d in
+ res.left
+
let union_of_values (n : Config_tree.t) (m : Config_tree.t) =
let set_n = ValueS.of_list (data_of n).values in
let set_m = ValueS.of_list (data_of m).values in