| 39 | |
| 40 | impl HookScriptsGuard { |
| 41 | fn execute_script_from_path<P: AsRef<Path>>(path: P) -> anyhow::Result<()> { |
| 42 | let path = path.as_ref(); |
| 43 | if !path.exists() || !path.is_file() { |
| 44 | debug!("Script not found or not a file: {}", path.display()); |
| 45 | return Ok(()); |
| 46 | } |
| 47 | |
| 48 | let output = Command::new("bash").args([&path]).output()?; |
| 49 | if !output.status.success() { |
| 50 | debug!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
| 51 | debug!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
| 52 | bail!("Failed to execute script: {}", path.display()); |
| 53 | } |
| 54 | |
| 55 | Ok(()) |
| 56 | } |
| 57 | |
| 58 | pub fn setup_with_scripts<P: AsRef<Path>>(pre_bench_script: P, post_bench_script: P) -> Self { |
| 59 | if let Err(e) = Self::execute_script_from_path(pre_bench_script.as_ref()) { |