diff options
author | John Estabrook <jestabro@vyos.io> | 2024-03-27 13:20:47 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2024-03-29 01:03:32 -0500 |
commit | be75413eaf4aef85274cc16c2283486799d99d73 (patch) | |
tree | f90528ad2df47376dbf1d72bb182e8a683788eb6 /src/config_diff.ml | |
parent | 406158f8557fd6ea88168357be1353fb58012b27 (diff) | |
download | vyos1x-config-be75413eaf4aef85274cc16c2283486799d99d73.tar.gz vyos1x-config-be75413eaf4aef85274cc16c2283486799d99d73.zip |
T6180: add ability to apply mask to config tree
Diffstat (limited to 'src/config_diff.ml')
-rw-r--r-- | src/config_diff.ml | 29 |
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 |