use anyhow::{anyhow, Result};
use std::path::{Path, PathBuf};
const VALIDATOR_DIR: &str = "knishio-validator-rust";
pub fn find_compose_file(start: &Path, compose_filename: &str) -> Option<PathBuf> {
let mut dir = start.to_path_buf();
loop {
let candidate = dir.join(compose_filename);
if candidate.exists() {
return Some(candidate);
}
let candidate = dir.join(VALIDATOR_DIR).join(compose_filename);
if candidate.exists() {
return Some(candidate);
}
let candidate = dir.join("servers").join(VALIDATOR_DIR).join(compose_filename);
if candidate.exists() {
return Some(candidate);
}
if !dir.pop() {
break;
}
}
None
}
pub fn find_compose_files(start: &Path, filenames: &[String]) -> Result<Vec<PathBuf>> {
if filenames.is_empty() {
return Err(anyhow!("no compose files configured for this accel profile"));
}
let mut resolved = Vec::with_capacity(filenames.len());
for name in filenames {
match find_compose_file(start, name) {
Some(path) => resolved.push(path),
None => {
return Err(anyhow!(
"compose file '{}' not found; walk up from {:?} didn't locate it \
under the validator tree. \
Did the overlay ship in this version of the repo?",
name,
start
));
}
}
}
Ok(resolved)
}