diff --git a/01_phase_rust_src/sv/src/executor.rs b/01_phase_rust_src/sv/src/executor.rs index 8fc94ad..7c738f8 100644 --- a/01_phase_rust_src/sv/src/executor.rs +++ b/01_phase_rust_src/sv/src/executor.rs @@ -1,14 +1,19 @@ use std::fs; +use std::path::Path; +use std::env::set_current_dir; pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec){ + // TODO: Return the exec code. println!("execute in exec"); dbg!(svdir_var.clone()); dbg!(svwait_var); dbg!(verbose); dbg!(command); + let mut exit_code: i32 = 0; + for sv in services { let ch1 = sv.chars().next().unwrap(); let ch2_row = &sv.chars().collect::>()[..2]; @@ -18,15 +23,29 @@ pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, s if ch1 == '/' || ch2 == "~/"{ // case absolute path for the service // - path = sv; + path = sv.clone(); } else { // case relative path for the service. // path = svdir_var.clone() + "/" + &sv; } - dbg!(path); - // 1. Check if path exists. - // + + // 1. Check if path exists. + // + let path_to_sv = Path::new(&path); + + if set_current_dir(path_to_sv).is_ok() { + println!("Set path okay."); + // TODO: make a function which do what's next. + // It will be called, sent_signal, will return 0 if no error, and 1 if an error. + } else { + println!("fail: {}: unable to change to service directory: file does not exist", sv); + if exit_code < 99 { + exit_code += 1; + } + } + + // TODO // 2. Check if supervise/ok exist // // if not, error => increase by one the exit code and print a beatifull message in Err