Bug: `mps delete` not working #20 #22

Merged
glitch4347 merged 1 commits from mpd-delete-not-working-#20 into main 3 months ago
  1. 12
      src/storage.rs

12
src/storage.rs

@ -132,8 +132,6 @@ impl Storage {
pub fn init(passphrase: String) -> io::Result<()> { pub fn init(passphrase: String) -> io::Result<()> {
Storage::check_installed()?; Storage::check_installed()?;
let db_path = paths::get_db_path()?;
fs::File::create(db_path)?;
let st = Storage::new(passphrase); let st = Storage::new(passphrase);
st.dump()?; st.dump()?;
println!("Storage db created"); println!("Storage db created");
@ -196,18 +194,26 @@ impl Storage {
} }
pub fn remove(&mut self, id: &String) { pub fn remove(&mut self, id: &String) {
for it in self.items.iter() {
println!("x: {}", it.id);
}
let item = Item::from_empty(id.clone()); let item = Item::from_empty(id.clone());
self.items.remove(&item); self.items.remove(&item);
for it in self.items.iter() {
println!("y: {}", it.id);
}
} }
pub fn dump(&self) -> io::Result<()> { pub fn dump(&self) -> io::Result<()> {
let mut file = fs::OpenOptions::new() let mut file = fs::OpenOptions::new()
.write(true) .write(true)
.append(false) .truncate(true) // Clear the file content before writing
.create(true)
.open(paths::get_db_path()?)?; .open(paths::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() {
println!("--- {}", item.id);
writeln!(file, "{}", self.encoder.encrypt(&item.id)?)?; writeln!(file, "{}", self.encoder.encrypt(&item.id)?)?;
let content = self.encoder.encrypt(&item.content)?; let content = self.encoder.encrypt(&item.content)?;
writeln!(file, "{}", content)?; writeln!(file, "{}", content)?;

Loading…
Cancel
Save