summaryrefslogtreecommitdiff
path: root/src/session.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/session.ml')
-rw-r--r--src/session.ml60
1 files changed, 44 insertions, 16 deletions
diff --git a/src/session.ml b/src/session.ml
index 5f70feb..f5fff2f 100644
--- a/src/session.ml
+++ b/src/session.ml
@@ -251,23 +251,51 @@ let save w s file =
| Error e -> raise (Session_error (Printf.sprintf "Error saving config: %s" e))
| Ok () -> s
-let prepare_commit ?(dry_run=false) w config id pid sudo_user user =
- let at = w.running_config in
- let rt = w.reference_tree in
+let write_running_cache w =
let vc = w.vyconf_config in
- let () =
- try
- IC.write_internal at (FP.concat vc.session_dir vc.running_cache)
- with
- Vyos1x.Internal.Write_error msg -> raise (Session_error msg)
- in
- let () =
- try
- IC.write_internal config (FP.concat vc.session_dir vc.session_cache)
- with
- Vyos1x.Internal.Write_error msg -> raise (Session_error msg)
- in
- CC.make_commit_data ~dry_run:dry_run rt at config id pid sudo_user user
+ try
+ let () =
+ IC.write_internal_atomic
+ w.running_config
+ (FP.concat vc.session_dir vc.running_cache);
+ in Ok ()
+ with
+ Vyos1x.Internal.Write_error msg ->
+ let msg =
+ Printf.sprintf "Write error caching running config: %s" msg
+ in Error msg
+
+let write_session_cache w config =
+ let vc = w.vyconf_config in
+ try
+ let () =
+ IC.write_internal
+ config
+ (FP.concat vc.session_dir vc.session_cache);
+ in Ok ()
+ with
+ Vyos1x.Internal.Write_error msg ->
+ let msg =
+ Printf.sprintf "Write error caching session config: %s" msg
+ in Error msg
+
+let prepare_commit ?(dry_run=false) w s config id =
+ let opt_running = write_running_cache w in
+ let opt_session = write_session_cache w config in
+ match opt_running, opt_session with
+ | Ok (), Ok () ->
+ Ok (CC.make_commit_data
+ ~dry_run:dry_run
+ w.reference_tree
+ w.running_config
+ config
+ id
+ s.client_pid
+ s.client_sudo_user
+ s.client_user)
+ | Error msg, Ok () -> Error msg
+ | Ok (), Error msg -> Error msg
+ | Error msg1, Error msg2 -> Error (Printf.sprintf "%s\n %s" msg1 msg2)
let post_process_commit w s ((c_data: CC.commit_data), proposed_config) =
let ident n v y =