41 lines
1.3 KiB
Rust
41 lines
1.3 KiB
Rust
/// 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<PathBuf> {
|
|
src.canonicalize()
|
|
}
|
|
|
|
fn prepare_work_dir(&self) -> io::Result<String> {
|
|
// 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<Vec<PathBuf>> {
|
|
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<std::process::ExitStatus> {
|
|
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<std::process::Output> {
|
|
Command::new(program).args(args).envs(env.iter().map(|(k, v)| (k, v))).output()
|
|
}
|
|
}
|