Various server improvements
This commit is contained in:
parent
3fe5f49050
commit
233ce1254b
10 changed files with 177 additions and 55 deletions
|
|
@ -28,23 +28,20 @@ pub struct Config {
|
|||
|
||||
impl Config {
|
||||
pub async fn read_or_create(path: &Path) -> Result<Self> {
|
||||
let config = if path.exists() {
|
||||
info!(
|
||||
"Loading configuration from `{}`",
|
||||
path.canonicalize().unwrap().display()
|
||||
);
|
||||
Self::load_from_file(path).await?
|
||||
let display_path = path.canonicalize().unwrap_or_else(|_| path.to_path_buf());
|
||||
|
||||
if path.exists() {
|
||||
info!("Loading configuration from `{}`", display_path.display());
|
||||
Self::load_from_file(path).await
|
||||
} else {
|
||||
Self::default()
|
||||
};
|
||||
|
||||
config.write(path).await?;
|
||||
info!(
|
||||
"Updated configuration at `{}`",
|
||||
path.canonicalize().unwrap().display()
|
||||
);
|
||||
|
||||
Ok(config)
|
||||
let config = Self::default();
|
||||
config.write(path).await?;
|
||||
info!(
|
||||
"Created default configuration at `{}`",
|
||||
display_path.display()
|
||||
);
|
||||
Ok(config)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn load_from_file(path: &Path) -> Result<Self> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue