diff options
| author | John Estabrook <jestabro@vyos.io> | 2026-04-10 15:08:07 -0500 |
|---|---|---|
| committer | John Estabrook <jestabro@vyos.io> | 2026-04-16 07:59:50 -0500 |
| commit | 460f2d895a6bf60e9c3b8aaabad3b5fccd2a379a (patch) | |
| tree | edd518959eb3b3b08f4c33ac1f1d8d9e7344a8dd /src/reference_tree.ml | |
| parent | 52132ad2c0992bf6f17a06173384030d93a29053 (diff) | |
| download | vyos1x-config-460f2d895a6bf60e9c3b8aaabad3b5fccd2a379a.tar.gz vyos1x-config-460f2d895a6bf60e9c3b8aaabad3b5fccd2a379a.zip | |
T8488: add utility refpath_from_partial
Infer the reference path from a path that may or may not contain
intervening tag nodes.
Return an empty list on a nonsensical path.
Diffstat (limited to 'src/reference_tree.ml')
| -rw-r--r-- | src/reference_tree.ml | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/reference_tree.ml b/src/reference_tree.ml index 8ff7b54..dead1be 100644 --- a/src/reference_tree.ml +++ b/src/reference_tree.ml @@ -648,6 +648,33 @@ let refpath reftree path = | _, [] -> acc in aux [] path +(* Convert from partial config path to reference tree path. + 'Partial' here means that there may or may not be intervening tag node + values. + *) +let refpath_from_partial reftree path = + let check_existence p = + match p with + | [] -> false + | _ -> (Vytree.exists[@alert "-exn"]) reftree p + in + let rec aux acc p = + match acc, p with + | [], h :: tl -> + if check_existence [h] then aux [h] tl else [] + | _, [h] -> + let p = acc @ [h] in + if check_existence p then p else + if is_tag reftree acc then acc else [] + | _, h :: h' :: tl -> + let p = acc @ [h] in + if check_existence p then aux p ([h'] @ tl) else + let p = acc @ [h'] in + if is_tag reftree acc && check_existence p then aux p tl + else [] + | _, [] -> acc + in aux [] path + let set_tag_data rtree ctree path = (* raises: [Vytree.Empty_path], |
