use std::fs;
use std::path::Path;
use camel_api::CamelError;
pub(crate) const MAX_ROUTE_FILE_SIZE: u64 = 16 * 1024 * 1024;
pub(crate) fn read_route_file_capped(path: &Path) -> Result<String, CamelError> {
let metadata = fs::metadata(path).map_err(|e| {
CamelError::Io(format!(
"Failed to read metadata of {}: {e}",
path.display()
))
})?;
if metadata.len() > MAX_ROUTE_FILE_SIZE {
return Err(CamelError::Io(format!(
"Route file `{}` is {} bytes, exceeds max {} bytes",
path.display(),
metadata.len(),
MAX_ROUTE_FILE_SIZE
)));
}
fs::read_to_string(path)
.map_err(|e| CamelError::Io(format!("Failed to read {}: {e}", path.display())))
}