diff options
author | John Estabrook <jestabro@vyos.io> | 2024-03-20 21:33:02 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2024-05-03 11:24:20 -0500 |
commit | bd73df56a46233aa007fee1c420023f44f5420fd (patch) | |
tree | 35928d4eda944bfcfbee04695af09fb35799afb7 | |
parent | 84720462dc1d77c7a5fbdf10e9c7db739aef1ce9 (diff) | |
download | vyos1x-config-bd73df56a46233aa007fee1c420023f44f5420fd.tar.gz vyos1x-config-bd73df56a46233aa007fee1c420023f44f5420fd.zip |
T6149: update node_data if necessary when merging nodes
(cherry picked from commit 7f7df88bbd4f58845ac272eb855e259eb82505d6)
-rw-r--r-- | src/reference_tree.ml | 7 | ||||
-rw-r--r-- | src/vytree.ml | 4 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index 302437e..7f6cc25 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -179,7 +179,12 @@ let rec insert_from_xml basepath reftree xml = let data = {data with node_type=node_type; owner=node_owner; default_value=default_value} in let name = Xml.attrib xml "name" in let path = basepath @ [name] in - let new_tree = Vytree.insert_maybe reftree path data in + let new_tree = + if data <> default_data then + Vytree.insert_or_update reftree path data + else + Vytree.insert_maybe reftree path data + in (match node_type with | Leaf -> new_tree | _ -> diff --git a/src/vytree.ml b/src/vytree.ml index ace587b..05b3088 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -167,6 +167,10 @@ let update node path data = replace node' child in do_with_child (update_data data) node path +let insert_or_update ?(position=Default) node path data = + try insert ~position:position node path data + with Duplicate_child -> update node path data + let rec get node path = match path with | [] -> raise Empty_path diff --git a/src/vytree.mli b/src/vytree.mli index a7bf680..412379a 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -25,6 +25,8 @@ val insert : ?position:position -> ?children:('a t list) -> 'a t -> string list val insert_maybe : ?position:position -> 'a t -> string list -> 'a -> 'a t +val insert_or_update : ?position:position -> 'a t -> string list -> 'a -> 'a t + val insert_multi_level : 'a -> 'a t -> string list -> string list -> 'a -> 'a t val merge_children : ('a -> 'a -> 'a) -> (string -> string -> int) -> 'a t -> 'a t |