1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use derive_more::AsRef;
use derive_more::Display;
use derive_more::From;
use derive_more::FromStr;
use derive_more::Into;
use std::path::Path;
use std::path::PathBuf;
const QUALIFIER: &str = "org";
const ORGANIZATION: &str = "holochain";
const APPLICATION: &str = "holochain";
const KEYS_DIRECTORY: &str = "keys";
const DATABASES_DIRECTORY: &str = "databases";
const CONFIG_FILENAME: &str = "conductor-config.yml";
#[derive(
Clone,
From,
Into,
Debug,
PartialEq,
AsRef,
FromStr,
Display,
serde::Serialize,
serde::Deserialize,
)]
#[display(fmt = "{}", "_0.display()")]
pub struct DatabaseRootPath(PathBuf);
impl Default for DatabaseRootPath {
fn default() -> Self {
Self(data_root().join(PathBuf::from(DATABASES_DIRECTORY)))
}
}
impl<'a> From<&'a Path> for DatabaseRootPath {
fn from(p: &'a Path) -> Self {
p.to_owned().into()
}
}
fn project_root() -> Option<directories::ProjectDirs> {
directories::ProjectDirs::from(QUALIFIER, ORGANIZATION, APPLICATION)
}
pub fn config_root() -> PathBuf {
project_root()
.map(|dirs| dirs.config_dir().to_owned())
.unwrap_or_else(|| PathBuf::from("/etc").join(APPLICATION))
}
pub fn data_root() -> PathBuf {
project_root()
.map(|dirs| dirs.data_dir().to_owned())
.unwrap_or_else(|| PathBuf::from("/etc").join(APPLICATION))
}
pub fn keys_directory() -> PathBuf {
config_root().join(KEYS_DIRECTORY)
}
#[derive(
Clone,
From,
Into,
Debug,
PartialEq,
AsRef,
FromStr,
Display,
serde::Serialize,
serde::Deserialize,
)]
#[display(fmt = "{}", "_0.display()")]
pub struct ConfigFilePath(PathBuf);
impl Default for ConfigFilePath {
fn default() -> Self {
Self(config_root().join(PathBuf::from(CONFIG_FILENAME)))
}
}