pub use holochain_keystore::paths::*;
use std::path::PathBuf;
pub const DATABASES_DIRECTORY: &str = "databases";
pub const WASM_DIRECTORY: &str = "wasm";
pub const CONDUCTOR_CONFIG: &str = "conductor-config.yaml";
#[derive(
shrinkwraprs::Shrinkwrap,
derive_more::From,
Debug,
PartialEq,
serde::Serialize,
serde::Deserialize,
Clone,
)]
pub struct ConfigRootPath(PathBuf);
impl ConfigRootPath {
pub fn is_also_data_root_path(&self) -> DataRootPath {
self.0.clone().into()
}
}
#[derive(
shrinkwraprs::Shrinkwrap,
derive_more::From,
Debug,
PartialEq,
serde::Serialize,
serde::Deserialize,
Clone,
)]
pub struct ConfigFilePath(PathBuf);
impl From<ConfigRootPath> for ConfigFilePath {
fn from(config_path: ConfigRootPath) -> Self {
Self::from(config_path.0.join(CONDUCTOR_CONFIG))
}
}
#[derive(
shrinkwraprs::Shrinkwrap,
derive_more::From,
Debug,
PartialEq,
serde::Serialize,
serde::Deserialize,
Clone,
)]
pub struct DataRootPath(PathBuf);
impl TryFrom<DataRootPath> for KeystorePath {
type Error = std::io::Error;
fn try_from(data_root_path: DataRootPath) -> Result<Self, Self::Error> {
let path = data_root_path.0.join(KEYSTORE_DIRECTORY);
if let Ok(false) = path.try_exists() {
std::fs::create_dir_all(path.clone())?;
}
Ok(Self::from(path))
}
}
#[derive(
shrinkwraprs::Shrinkwrap,
derive_more::From,
Debug,
PartialEq,
serde::Serialize,
serde::Deserialize,
Clone,
)]
pub struct DatabasesRootPath(PathBuf);
impl TryFrom<DataRootPath> for DatabasesRootPath {
type Error = std::io::Error;
fn try_from(data_path: DataRootPath) -> Result<Self, Self::Error> {
let path = data_path.0.join(DATABASES_DIRECTORY);
if let Ok(false) = path.try_exists() {
std::fs::create_dir_all(path.clone())?;
}
Ok(Self::from(path))
}
}
#[derive(
shrinkwraprs::Shrinkwrap,
derive_more::From,
Debug,
PartialEq,
serde::Serialize,
serde::Deserialize,
Clone,
)]
pub struct WasmRootPath(PathBuf);
impl TryFrom<DataRootPath> for WasmRootPath {
type Error = std::io::Error;
fn try_from(data_path: DataRootPath) -> Result<Self, Self::Error> {
let path = data_path.0.join(WASM_DIRECTORY);
if let Ok(false) = path.try_exists() {
std::fs::create_dir_all(path.clone())?;
}
Ok(Self::from(path))
}
}