diff options
author | John Estabrook <jestabro@vyos.io> | 2023-05-01 11:04:47 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-05-10 22:52:25 -0500 |
commit | 782d945950e52a8b48b812b0fad6161e43f7f5b0 (patch) | |
tree | 60037f64154d27650a2730f447407e93480d1c71 | |
parent | b6474d84fbe2134798049d6c5915b7382e7043aa (diff) | |
download | vyos1x-config-782d945950e52a8b48b812b0fad6161e43f7f5b0.tar.gz vyos1x-config-782d945950e52a8b48b812b0fad6161e43f7f5b0.zip |
T5194: insert_maybe as node names exist in multiple interface-def files
-rw-r--r-- | src/reference_tree.ml | 2 | ||||
-rw-r--r-- | src/vytree.ml | 4 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
3 files changed, 7 insertions, 1 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index f61feaa..24e02a5 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -118,7 +118,7 @@ let rec insert_from_xml basepath reftree xml = let data = {data with node_type=node_type; owner=node_owner} in let name = Xml.attrib xml "name" in let path = basepath @ [name] in - let new_tree = Vytree.insert reftree path data in + let new_tree = 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 bd73776..ace587b 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -88,6 +88,10 @@ let rec insert ?(position=Default) ?(children=[]) node path data = let s = Printf.sprintf "Non-existent intermediary node: \'%s\'" name in raise (Insert_error s) +let insert_maybe ?(position=Default) node path data = + try insert ~position:position node path data + with Duplicate_child -> node + let sorted_children_of_node cmp node = let names = list_children node in let names = List.sort cmp names in diff --git a/src/vytree.mli b/src/vytree.mli index 377c9aa..a7bf680 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -23,6 +23,8 @@ val replace : 'a t -> 'a t -> 'a t val insert : ?position:position -> ?children:('a t list) -> 'a t -> string list -> 'a -> 'a t +val insert_maybe : ?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 |