|
|
@ -3,7 +3,11 @@ use std::{
|
|
|
|
path::{
|
|
|
|
path::{
|
|
|
|
PathBuf,
|
|
|
|
PathBuf,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
error,
|
|
|
|
|
|
|
|
fmt,
|
|
|
|
|
|
|
|
io
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
use tokio::fs;
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
|
|
pub struct Config
|
|
|
|
pub struct Config
|
|
|
@ -17,8 +21,55 @@ impl Default for Config
|
|
|
|
fn default() -> Self
|
|
|
|
fn default() -> Self
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Self {
|
|
|
|
Self {
|
|
|
|
base_dir: PathBuf::default(),
|
|
|
|
base_dir: PathBuf::from("/tmp/videl"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Config
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/// Validate this config
|
|
|
|
|
|
|
|
pub async fn validate(&self) -> Result<(), Error>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let exists = self.base_dir.exists();
|
|
|
|
|
|
|
|
if exists && !self.base_dir.is_dir() {
|
|
|
|
|
|
|
|
return Err(Error::InvalidDestination);
|
|
|
|
|
|
|
|
} else if !exists {
|
|
|
|
|
|
|
|
fs::create_dir_all(&self.base_dir).await?;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
|
|
|
|
pub enum Error {
|
|
|
|
|
|
|
|
IO(io::Error),
|
|
|
|
|
|
|
|
InvalidDestination,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl error::Error for Error
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
|
|
|
|
|
|
|
|
match &self {
|
|
|
|
|
|
|
|
Self::IO(io) => Some(io),
|
|
|
|
|
|
|
|
_ => None,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Error
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::IO(_) => write!(f, "i/o error"),
|
|
|
|
|
|
|
|
Self::InvalidDestination => write!(f, "invalid base destination for videl databases"),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<io::Error> for Error
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
#[inline] fn from(from: io::Error) -> Self
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Self::IO(from)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|