simplifying apply_migrations

This commit is contained in:
Dietrich 2021-04-12 16:30:18 +02:00
parent a3b757abad
commit ac172670be
Signed by: dietrich
GPG Key ID: 9F3C20C0F85DF67C

View File

@ -327,22 +327,25 @@ async fn apply_migrations(config: &ServerConfig) -> Result<(), ServerError> {
fn generate_env_file(server_config: &ServerConfig) -> Result<(), ServerError> { fn generate_env_file(server_config: &ServerConfig) -> Result<(), ServerError> {
if std::path::Path::new(".env").exists() { if std::path::Path::new(".env").exists() {
error!("ERROR: There already is a .env file - ABORT!") return Err(ServerError::User(
} else { "ERROR: There already is a .env file - ABORT!".to_string(),
info!("Creating a .env file with default options");
info!(concat!(
"The SECRET_KEY variable is used for password encryption.",
"If it is changed all existing passwords are invalid."
)); ));
let mut file = std::fs::File::create(".env")?; }
info!(
r#"Creating a .env file with default options
The SECRET_KEY variable is used for password encryption.
If it is changed all existing passwords are invalid."#
);
let mut file = std::fs::File::create(".env")?;
let conf_file_content = server_config.to_env_strings(); let conf_file_content = server_config.to_env_strings();
conf_file_content.iter().for_each(|l| { for line in &conf_file_content {
file.write_all(l.as_bytes()) file.write_all(line.as_bytes())
.expect("failed to write .env file") .expect("failed to write .env file")
});
info!("Successfully created the env file!")
} }
info!("Successfully created the env file!");
Ok(()) Ok(())
} }