From 36f77b3edb00d74317efc39b2eeaf2551cc0cc83 Mon Sep 17 00:00:00 2001 From: primardj Date: Sun, 7 Apr 2024 22:01:39 +0100 Subject: [PATCH] make a good path for a service --- 01_phase_rust_src/sv/src/executor.rs | 33 ++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/01_phase_rust_src/sv/src/executor.rs b/01_phase_rust_src/sv/src/executor.rs index 6641cc9..8fc94ad 100644 --- a/01_phase_rust_src/sv/src/executor.rs +++ b/01_phase_rust_src/sv/src/executor.rs @@ -1,11 +1,40 @@ +use std::fs; + pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec){ println!("execute in exec"); - dbg!(svdir_var); + dbg!(svdir_var.clone()); dbg!(svwait_var); dbg!(verbose); dbg!(command); - dbg!(services); + + for sv in services { + let ch1 = sv.chars().next().unwrap(); + let ch2_row = &sv.chars().collect::>()[..2]; + let ch2: String = ch2_row.into_iter().collect(); + let path; + + if ch1 == '/' || ch2 == "~/"{ + // case absolute path for the service + // + path = sv; + } else { + // case relative path for the service. + // + path = svdir_var.clone() + "/" + &sv; + } + dbg!(path); + // 1. Check if path exists. + // + // 2. Check if supervise/ok exist + // + // if not, error => increase by one the exit code and print a beatifull message in Err + // standard. + // + // if yes, sent the proper signal to supervise/control + // + // if verbose = 1, wait for the service to reach the proper state or timeout. + } }