From e19cd571f949d2bd76ed1a3671be8e122b32dae3 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Fri, 27 Sep 2024 00:24:02 +0000 Subject: [PATCH] init withoud db #24 --- src/storage.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/storage.rs b/src/storage.rs index cb29836..7d78344 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -131,9 +131,11 @@ impl Storage { } pub fn init(passphrase: String) -> io::Result<()> { - Storage::check_installed()?; + //Storage::check_installed()?; + let sp = paths::get_storage_path()?; + fs::create_dir(sp)?; let st = Storage::new(passphrase); - st.dump()?; + st.dump_db()?; println!("Storage db created"); Ok(()) } @@ -159,7 +161,7 @@ impl Storage { } pub fn is_inited() -> io::Result { - Storage::check_installed()?; + //Storage::check_installed()?; let db = paths::get_db_path()?; let db_path = Path::new(&db); Ok(db_path.exists()) @@ -199,6 +201,12 @@ impl Storage { } pub fn dump(&self) -> io::Result<()> { + self.dump_db()?; + git::Git::sync()?; + Ok(()) + } + + fn dump_db(&self) -> io::Result<()> { let mut file = fs::OpenOptions::new() .write(true) .truncate(true) // Clear the file content before writing @@ -211,8 +219,8 @@ impl Storage { let content = self.encoder.encrypt(&item.content)?; writeln!(file, "{}", content)?; } - git::Git::sync()?; Ok(()) } + }