Create config file on startup
This commit is contained in:
parent
5f585a61d8
commit
142d400b8b
1 changed files with 19 additions and 5 deletions
|
@ -96,9 +96,27 @@ impl Manager {
|
||||||
auth_secret,
|
auth_secret,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if !tokio::fs::try_exists(config_file_path)
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::Io(config_file_path.to_owned(), e))?
|
||||||
|
{
|
||||||
|
manager.save_config().await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(manager)
|
Ok(manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn save_config(&self) -> Result<(), Error> {
|
||||||
|
let serialized = toml::ser::to_string_pretty::<storage::Config>(
|
||||||
|
&self.config.read().await.clone().into(),
|
||||||
|
)
|
||||||
|
.map_err(Error::ConfigSerialization)?;
|
||||||
|
tokio::fs::write(&self.config_file_path, serialized.as_bytes())
|
||||||
|
.await
|
||||||
|
.map_err(|e| Error::Io(self.config_file_path.clone(), e))?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub async fn apply(&self, config: storage::Config) -> Result<(), Error> {
|
pub async fn apply(&self, config: storage::Config) -> Result<(), Error> {
|
||||||
self.mutate_fallible(|c| {
|
self.mutate_fallible(|c| {
|
||||||
|
@ -122,11 +140,7 @@ impl Manager {
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let mut config = self.config.write().await;
|
let mut config = self.config.write().await;
|
||||||
op(&mut config)?;
|
op(&mut config)?;
|
||||||
let serialized = toml::ser::to_string_pretty::<storage::Config>(&config.clone().into())
|
self.save_config().await?;
|
||||||
.map_err(Error::ConfigSerialization)?;
|
|
||||||
tokio::fs::write(&self.config_file_path, serialized.as_bytes())
|
|
||||||
.await
|
|
||||||
.map_err(|e| Error::Io(self.config_file_path.clone(), e))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue