Browse Source

init++

fix-typo
Coin de Gamma 3 months ago
parent
commit
6dd1bc7d04
  1. 2
      README.md
  2. 7
      src/main.rs
  3. 21
      src/storage.rs

2
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/<your_username>/.mps"`
4. Add to your $PATH:<path_to_msp> where you installed your mps
5. Run ./mps init

7
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/<your_username>/.mps\"`");
println!("4. Add to your $PATH:<path_to_msp> 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)?;

21
src/storage.rs

@ -90,7 +90,7 @@ impl Storage {
Ok(result)
}
fn get_storage_db_path() -> io::Result<String> {
fn get_db_path() -> io::Result<String> {
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::<Item>::new();
let mut id: Option<String> = None;
@ -159,7 +159,7 @@ impl Storage {
Ok(())
}
pub fn is_inited() -> io::Result<bool> {
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<bool> {
Storage::check_installed()?;
let db = Storage::get_db_path()?;
let db_path = Path::new(&db);
Ok(db_path.exists())
}
pub fn ids(&self) -> Vec<String> {
@ -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() {

Loading…
Cancel
Save