Implement insert and edit sessions (#7)
This commit is contained in:
@@ -37,6 +37,10 @@ impl EntryPath {
|
||||
&self.0
|
||||
}
|
||||
|
||||
pub fn parent_directory(&self) -> DirectoryPath {
|
||||
self.parent()
|
||||
}
|
||||
|
||||
fn parent(&self) -> DirectoryPath {
|
||||
DirectoryPath(self.0.parent().map_or_else(PathBuf::new, Path::to_path_buf))
|
||||
}
|
||||
@@ -511,6 +515,20 @@ impl Repository {
|
||||
self.write_entry_with_checkpoint(path, ciphertext, |_| Ok(()))
|
||||
}
|
||||
|
||||
pub fn remove_entry(&self, path: &EntryPath) -> Result<EncryptedEntry, RepositoryError> {
|
||||
let original = self.read_entry(path)?;
|
||||
let (parent, file_name) = self.open_entry_parent(path)?;
|
||||
parent
|
||||
.remove_file(&file_name)
|
||||
.map_err(|error| io_error("remove encrypted entry", &path.0, error))?;
|
||||
sync_directory(&parent, &path.parent().0).map_err(|_| {
|
||||
RepositoryError::DurabilityUncertain {
|
||||
path: path.0.clone(),
|
||||
}
|
||||
})?;
|
||||
Ok(original)
|
||||
}
|
||||
|
||||
fn write_entry_with_checkpoint<F>(
|
||||
&self,
|
||||
path: &EntryPath,
|
||||
|
||||
Reference in New Issue
Block a user