From 30dae4d19bdfa22c36e50a94ea157168311e2a8e Mon Sep 17 00:00:00 2001 From: Itamar Perez Date: Sat, 1 Jun 2024 17:56:38 -0700 Subject: [PATCH 1/3] Add calling setup_db function to create database if it doesn't exist --- src/core.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core.rs b/src/core.rs index a9fccab..df9930a 100644 --- a/src/core.rs +++ b/src/core.rs @@ -393,6 +393,14 @@ pub fn run_core() -> Subscription { let db_path = path.join("harbor.sqlite"); let db_path = db_path.to_str().unwrap().to_string(); + + // if the db file doesn't exist, call setup_db + if !std::path::Path::new(&db_path).exists() { + if let Err(e) = setup_db(&db_path, password.clone()) { + error!("error setting up db: {e}"); + } + } + if let Err(e) = check_password(&db_path, &password) { // probably invalid password error!("error using password: {e}"); From 57c36116a263b6e65789f131c787117610e5d7ec Mon Sep 17 00:00:00 2001 From: Itamar Perez Date: Sat, 1 Jun 2024 18:37:51 -0700 Subject: [PATCH 2/3] skip check_password if db file does not exist --- src/core.rs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/src/core.rs b/src/core.rs index df9930a..1a637fa 100644 --- a/src/core.rs +++ b/src/core.rs @@ -19,7 +19,7 @@ use iced::{ futures::{channel::mpsc::Sender, SinkExt}, subscription::{self, Subscription}, }; -use log::{error, trace, warn}; +use log::{error, info, trace, warn}; use tokio::sync::RwLock; use tokio::task::spawn_blocking; use uuid::Uuid; @@ -396,26 +396,24 @@ pub fn run_core() -> Subscription { // if the db file doesn't exist, call setup_db if !std::path::Path::new(&db_path).exists() { - if let Err(e) = setup_db(&db_path, password.clone()) { - error!("error setting up db: {e}"); + info!("Database does not exist, it will be created"); + } else { + if let Err(e) = check_password(&db_path, &password) { + // probably invalid password + error!("error using password: {e}"); + + tx.send(Message::core_msg( + id, + CoreUIMsg::UnlockFailed(e.to_string()), + )) + .await + .expect("should send"); + continue; } - } - - if let Err(e) = check_password(&db_path, &password) { - // probably invalid password - error!("error using password: {e}"); - tx.send(Message::core_msg( - id, - CoreUIMsg::UnlockFailed(e.to_string()), - )) - .await - .expect("should send"); - continue; + log::info!("Correct password"); } - log::info!("Correct password"); - let db = spawn_blocking(move || setup_db(&db_path, password)) .await .expect("Could not create join handle"); From fddaaac7ae2fc9b7bc54d9c9b53cb44935091f46 Mon Sep 17 00:00:00 2001 From: Itamar Perez Date: Sat, 1 Jun 2024 18:39:42 -0700 Subject: [PATCH 3/3] fix comment --- src/core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core.rs b/src/core.rs index 1a637fa..a8a301f 100644 --- a/src/core.rs +++ b/src/core.rs @@ -394,7 +394,7 @@ pub fn run_core() -> Subscription { let db_path = db_path.to_str().unwrap().to_string(); - // if the db file doesn't exist, call setup_db + // if the db file doesn't exist, dont call check_password if !std::path::Path::new(&db_path).exists() { info!("Database does not exist, it will be created"); } else {