From d8eb9018a7a8699d491ec2be9cb0336e40f6a413 Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Tue, 24 Sep 2024 06:52:13 +0000 Subject: [PATCH] truncate db --- src/storage.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/storage.rs b/src/storage.rs index 312e201..0dea946 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -132,8 +132,6 @@ impl Storage { pub fn init(passphrase: String) -> io::Result<()> { Storage::check_installed()?; - let db_path = paths::get_db_path()?; - fs::File::create(db_path)?; let st = Storage::new(passphrase); st.dump()?; println!("Storage db created"); @@ -196,18 +194,26 @@ impl Storage { } pub fn remove(&mut self, id: &String) { + for it in self.items.iter() { + println!("x: {}", it.id); + } let item = Item::from_empty(id.clone()); self.items.remove(&item); + for it in self.items.iter() { + println!("y: {}", it.id); + } } pub fn dump(&self) -> io::Result<()> { let mut file = fs::OpenOptions::new() .write(true) - .append(false) + .truncate(true) // Clear the file content before writing + .create(true) .open(paths::get_db_path()?)?; writeln!(file, "{}", self.encoder.get_encoded_test_passphrase()?)?; for item in self.items.iter() { + println!("--- {}", item.id); writeln!(file, "{}", self.encoder.encrypt(&item.id)?)?; let content = self.encoder.encrypt(&item.content)?; writeln!(file, "{}", content)?; -- 2.34.1