/// Local context: execute commands locally /// Context driver: Does nothing use super::api::ContextDriver; use std::io; use std::path::{Path, PathBuf}; use std::process::Command; pub struct LocalDriver; impl ContextDriver for LocalDriver { fn ensure_available(&self, src: &Path, _dest_root: &str) -> io::Result { src.canonicalize() } fn prepare_work_dir(&self) -> io::Result { // TODO: Fix that, we should not always use '..' as work directory locally Ok("..".to_string()) } fn retrieve_path(&self, _src: &Path, _dest: &Path) -> io::Result<()> { Ok(()) } fn list_files(&self, path: &Path) -> io::Result> { let mut entries = Vec::new(); for entry in std::fs::read_dir(path)? { let entry = entry?; entries.push(entry.path()); } Ok(entries) } fn run(&self, program: &str, args: &[String], env: &[(String, String)]) -> io::Result { Command::new(program).args(args).envs(env.iter().map(|(k, v)| (k, v))).status() } fn run_output(&self, program: &str, args: &[String], env: &[(String, String)]) -> io::Result { Command::new(program).args(args).envs(env.iter().map(|(k, v)| (k, v))).output() } }