Skip to content

Commit

Permalink
skip check_password if db file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
esomore committed Jun 2, 2024
1 parent 30dae4d commit 57c3611
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -396,26 +396,24 @@ pub fn run_core() -> Subscription<Message> {

// 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");
Expand Down

0 comments on commit 57c3611

Please sign in to comment.