Browse Source

init withoud db #24

item-number-refactoring
Coin de Gamma 3 months ago
parent
commit
e19cd571f9
  1. 16
      src/storage.rs

16
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<bool> {
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(())
}
}

Loading…
Cancel
Save