From 6dd1bc7d04988d076faaf960e89f58e038112db2 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Fri, 20 Sep 2024 09:14:14 +0000 Subject: [PATCH] init++ --- README.md | 2 +- src/main.rs | 7 +++++-- src/storage.rs | 21 +++++++++++++-------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 9a12570..13f6ab2 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ A small tool for storing passwords locally with git sync 1. Create empty repository for storing your passwords on gitlab or somewhere you prefer 2. Clone to your home folder ~/.mps/storage -3. Set variable $MPS_HOME="~/.mps/" +3. Export varable $MPS_HOME: `export MPS_HOME="/home//.mps"` 4. Add to your $PATH: where you installed your mps 5. Run ./mps init diff --git a/src/main.rs b/src/main.rs index 07a9ed5..4451f2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,7 +81,7 @@ impl MPS { fn print_init_hint() { println!("1. Create empty repository for storing your passwords on gitlab or somewhere you prefer"); println!("2. Clone to your home folder ~/.mps/storage"); - println!("3. Set variable $MPS_HOME=\"~/.mps/\""); + println!("3. xport varable $MPS_HOME: `export MPS_HOME=\"/home//.mps\"`"); println!("4. Add to your $PATH: where you installed your mps"); println!("5. Run mps init"); } @@ -116,7 +116,10 @@ impl MPS { passphrase = ps; break; }, - Err(_) => continue + Err(e) => { + println!("{}", e); + continue + } } } Storage::init(passphrase)?; diff --git a/src/storage.rs b/src/storage.rs index e553347..a03b0bd 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -90,7 +90,7 @@ impl Storage { Ok(result) } - fn get_storage_db_path() -> io::Result { + fn get_db_path() -> io::Result { let st = Storage::get_storage_path()?; let result = format!("{}/{}", st, PATH_DB); Ok(result) @@ -104,7 +104,7 @@ impl Storage { )); } let encoder = Encoder::from(&passphrase); - let file = fs::File::open(Storage::get_storage_db_path()?)?; + let file = fs::File::open(Storage::get_db_path()?)?; let reader = io::BufReader::new(file); let mut items = HashSet::::new(); let mut id: Option = None; @@ -159,7 +159,7 @@ impl Storage { Ok(()) } - pub fn is_inited() -> io::Result { + pub fn check_installed() -> io::Result<()> { let sp = Storage::get_storage_path()?; let storage_path = Path::new(&sp); // Check if the folder exists and is a directory @@ -169,12 +169,17 @@ impl Storage { format!("{} does not exist or not a dir", Storage::get_storage_path()?) )); } + + Ok(()) // TODO check git - //let path = Path::new(&*STORAGE_FOLDER); - //return path.exists(); - Ok(true) - + } + + pub fn is_inited() -> io::Result { + Storage::check_installed()?; + let db = Storage::get_db_path()?; + let db_path = Path::new(&db); + Ok(db_path.exists()) } pub fn ids(&self) -> Vec { @@ -209,7 +214,7 @@ impl Storage { let mut file = fs::OpenOptions::new() .write(true) .append(false) - .open(Storage::get_storage_db_path()?)?; + .open(Storage::get_db_path()?)?; writeln!(file, "{}", self.encoder.get_encoded_test_passphrase()?)?; for item in self.items.iter() {