mirror of
https://github.com/ViViDboarder/bitwarden_rs.git
synced 2024-11-22 13:16:39 +00:00
Check that the database folder exists before connecting
If the parent folder ('data' by default) doesn't exist, the database won't be able to connect.
This commit is contained in:
parent
ba8a1c27f7
commit
fcef2fa1f1
25
src/main.rs
25
src/main.rs
@ -25,7 +25,7 @@ extern crate dotenv;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
use std::{io, env};
|
use std::{io, env, path::Path, process::{exit, Command}};
|
||||||
use rocket::Rocket;
|
use rocket::Rocket;
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
@ -51,22 +51,34 @@ fn init_rocket() -> Rocket {
|
|||||||
embed_migrations!();
|
embed_migrations!();
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
check_db();
|
||||||
|
check_rsa_keys();
|
||||||
|
check_web_vault();
|
||||||
|
|
||||||
// Make sure the database is up to date (create if it doesn't exist, or run the migrations)
|
// Make sure the database is up to date (create if it doesn't exist, or run the migrations)
|
||||||
let connection = db::get_connection().expect("Can't conect to DB");
|
let connection = db::get_connection().expect("Can't conect to DB");
|
||||||
embedded_migrations::run_with_output(&connection, &mut io::stdout()).expect("Can't run migrations");
|
embedded_migrations::run_with_output(&connection, &mut io::stdout()).expect("Can't run migrations");
|
||||||
|
|
||||||
check_rsa_keys();
|
|
||||||
check_web_vault();
|
|
||||||
|
|
||||||
init_rocket().launch();
|
init_rocket().launch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_db() {
|
||||||
|
let path = Path::new(&CONFIG.database_url);
|
||||||
|
|
||||||
|
if let Some(parent) = path.parent() {
|
||||||
|
use std::fs;
|
||||||
|
if fs::create_dir_all(parent).is_err() {
|
||||||
|
println!("Error creating database directory");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn check_rsa_keys() {
|
fn check_rsa_keys() {
|
||||||
// If the RSA keys don't exist, try to create them
|
// If the RSA keys don't exist, try to create them
|
||||||
if !util::file_exists(&CONFIG.private_rsa_key)
|
if !util::file_exists(&CONFIG.private_rsa_key)
|
||||||
|| !util::file_exists(&CONFIG.public_rsa_key) {
|
|| !util::file_exists(&CONFIG.public_rsa_key) {
|
||||||
println!("JWT keys don't exist, checking if OpenSSL is available...");
|
println!("JWT keys don't exist, checking if OpenSSL is available...");
|
||||||
use std::process::{exit, Command};
|
|
||||||
|
|
||||||
Command::new("openssl")
|
Command::new("openssl")
|
||||||
.arg("version")
|
.arg("version")
|
||||||
@ -108,9 +120,6 @@ fn check_rsa_keys() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_web_vault() {
|
fn check_web_vault() {
|
||||||
use std::path::Path;
|
|
||||||
use std::process::exit;
|
|
||||||
|
|
||||||
let index_path = Path::new(&CONFIG.web_vault_folder).join("index.html");
|
let index_path = Path::new(&CONFIG.web_vault_folder).join("index.html");
|
||||||
|
|
||||||
if !index_path.exists() {
|
if !index_path.exists() {
|
||||||
|
Loading…
Reference in New Issue
Block a user