|
|
|
@ -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)?; |
|
|
|
|