|
|
@ -90,7 +90,7 @@ impl Storage { |
|
|
|
Ok(result) |
|
|
|
Ok(result) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_storage_db_path() -> io::Result<String> { |
|
|
|
fn get_db_path() -> io::Result<String> { |
|
|
|
let st = Storage::get_storage_path()?; |
|
|
|
let st = Storage::get_storage_path()?; |
|
|
|
let result = format!("{}/{}", st, PATH_DB); |
|
|
|
let result = format!("{}/{}", st, PATH_DB); |
|
|
|
Ok(result) |
|
|
|
Ok(result) |
|
|
@ -104,7 +104,7 @@ impl Storage { |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
let encoder = Encoder::from(&passphrase); |
|
|
|
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 reader = io::BufReader::new(file); |
|
|
|
let mut items = HashSet::<Item>::new(); |
|
|
|
let mut items = HashSet::<Item>::new(); |
|
|
|
let mut id: Option<String> = None; |
|
|
|
let mut id: Option<String> = None; |
|
|
@ -159,7 +159,7 @@ impl Storage { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn is_inited() -> io::Result<bool> { |
|
|
|
pub fn check_installed() -> io::Result<()> { |
|
|
|
let sp = Storage::get_storage_path()?; |
|
|
|
let sp = Storage::get_storage_path()?; |
|
|
|
let storage_path = Path::new(&sp); |
|
|
|
let storage_path = Path::new(&sp); |
|
|
|
// Check if the folder exists and is a directory
|
|
|
|
// 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()?) |
|
|
|
format!("{} does not exist or not a dir", Storage::get_storage_path()?) |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
|
|
|
|
// TODO check git
|
|
|
|
// 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> { |
|
|
|
pub fn ids(&self) -> Vec<String> { |
|
|
@ -209,7 +214,7 @@ impl Storage { |
|
|
|
let mut file = fs::OpenOptions::new() |
|
|
|
let mut file = fs::OpenOptions::new() |
|
|
|
.write(true) |
|
|
|
.write(true) |
|
|
|
.append(false) |
|
|
|
.append(false) |
|
|
|
.open(Storage::get_storage_db_path()?)?; |
|
|
|
.open(Storage::get_db_path()?)?; |
|
|
|
writeln!(file, "{}", self.encoder.get_encoded_test_passphrase()?)?; |
|
|
|
writeln!(file, "{}", self.encoder.get_encoded_test_passphrase()?)?; |
|
|
|
|
|
|
|
|
|
|
|
for item in self.items.iter() { |
|
|
|
for item in self.items.iter() { |
|
|
|