From d366f8e302ddadf9ad6ee74ca5430dcc52a7c67b Mon Sep 17 00:00:00 2001 From: John Estabrook Date: Sun, 16 Mar 2025 22:31:02 -0500 Subject: T7121: keep track of source of subtree from delete or add trees For partial commits with a config error on a subtree, one needs to know the origin of the failed subtree, whether from deletion or addition, in order to contruct the partial successful result. --- src/commit.ml | 27 ++++++++++++++++++--------- src/commit.mli | 7 +++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/commit.ml b/src/commit.ml index c8cb43e..a2b9f6e 100644 --- a/src/commit.ml +++ b/src/commit.ml @@ -4,10 +4,16 @@ module CD = Vyos1x.Config_diff module RT = Vyos1x.Reference_tree module FP = FilePath +type tree_source = DELETE | ADD + +let tree_source_to_yojson = function + | DELETE -> `String "DELETE" + | ADD -> `String "ADD" + type status = { success : bool; out : string; -} [@@deriving yojson] +} [@@deriving to_yojson] type node_data = { script_name: string; @@ -15,8 +21,9 @@ type node_data = { tag_value: string option; arg_value: string option; path: string list; + source: tree_source; reply: status option; -} [@@deriving yojson] +} [@@deriving to_yojson] let default_node_data = { @@ -25,6 +32,7 @@ let default_node_data = { tag_value = None; arg_value = None; path = []; + source = ADD; reply = Some { success = false; out = ""; }; } @@ -37,7 +45,7 @@ type commit_data = { background: bool; init: status option; node_list: node_data list; -} [@@deriving yojson] +} [@@deriving to_yojson] let default_commit_data = { session_id = ""; @@ -84,7 +92,7 @@ let owner_args_from_data p o = let add_tag_instance cd cs tv = CS.add { cd with tag_value = Some tv; } cs -let get_node_data rt ct (path, cs') t = +let get_node_data rt ct src (path, cs') t = if Vyos1x.Util.is_empty path then (path, cs') else @@ -112,7 +120,8 @@ let get_node_data rt ct (path, cs') t = script_name = own; priority = priority; arg_value = arg; - path = rpath; } + path = rpath; + source = src; } in let tag_values = match RT.is_tag rt rt_path with @@ -125,8 +134,8 @@ let get_node_data rt ct (path, cs') t = | _ -> List.fold_left (add_tag_instance c_data) cs' tag_values in (path, cs) -let get_commit_set rt ct = - snd (VT.fold_tree_with_path (get_node_data rt ct) ([], CS.empty) ct) +let get_commit_set rt ct src = + snd (VT.fold_tree_with_path (get_node_data rt ct src) ([], CS.empty) ct) (* for initial consistency with the legacy ordering of delete and add queues, enforce the following subtlety: if a path in the delete tree is @@ -150,8 +159,8 @@ let calculate_priority_lists rt at wt = let diff = CD.diff_tree [] at wt in let del_tree = CD.get_tagged_delete_tree diff in let add_tree = CT.get_subtree diff ["add"] in - let cs_del' = get_commit_set rt del_tree in - let cs_add' = get_commit_set rt add_tree in + let cs_del' = get_commit_set rt del_tree DELETE in + let cs_add' = get_commit_set rt add_tree ADD in let cs_del, cs_add = legacy_order del_tree cs_del' cs_add' in List.rev (CS.elements cs_del), CS.elements cs_add diff --git a/src/commit.mli b/src/commit.mli index e765f48..da97389 100644 --- a/src/commit.mli +++ b/src/commit.mli @@ -1,3 +1,5 @@ +type tree_source = DELETE | ADD + type status = { success : bool; out : string; @@ -9,8 +11,9 @@ type node_data = { tag_value: string option; arg_value: string option; path: string list; + source: tree_source; reply: status option; -} [@@deriving yojson] +} [@@deriving to_yojson] type commit_data = { session_id: string; @@ -21,7 +24,7 @@ type commit_data = { background: bool; init: status option; node_list: node_data list; -} [@@deriving yojson] +} [@@deriving to_yojson] val default_node_data : node_data -- cgit v1.2.3