From c679d4bf744759b5a84044fc766578b382b1837b Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Tue, 17 Sep 2024 18:04:39 +0000 Subject: [PATCH] check inited in storage --- src/storage.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/storage.rs b/src/storage.rs index 2327b59..e92fb63 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -110,7 +110,12 @@ impl Storage { } } pub fn from_db(passphrase: String) -> io::Result { - // TODO: throw error if it's not inited + if !Storage::is_inited() { + return Err(io::Error::new( + io::ErrorKind::Other, + "Storage is not initialized" + )); + } let encoder = Encoder::from(passphrase); // TODO: throw error is password is incorrect let file = fs::File::open(&*STORAGE_PATH)?; @@ -173,8 +178,11 @@ impl Storage { } pub fn is_inited() -> bool { + // TODO: check db + // TODO check git let path = Path::new(&*STORAGE_FOLDER); return path.exists(); + } pub fn ids(&self) -> Vec {