Provide unlink() to remove all links
This commit is contained in:
parent
1521005e79
commit
6055520519
1 changed files with 15 additions and 0 deletions
|
@ -24,6 +24,7 @@ use std::path::PathBuf;
|
|||
use libimagstore::storeid::StoreId;
|
||||
use libimagstore::storeid::IntoStoreId;
|
||||
use libimagstore::store::Entry;
|
||||
use libimagstore::store::Store;
|
||||
use libimagstore::store::Result as StoreResult;
|
||||
|
||||
use toml_query::read::TomlValueReadExt;
|
||||
|
@ -178,6 +179,9 @@ pub trait InternalLinker {
|
|||
/// Remove an internal link from the implementor object
|
||||
fn remove_internal_link(&mut self, link: &mut Entry) -> Result<()>;
|
||||
|
||||
/// Remove _all_ internal links
|
||||
fn unlink(&mut self, store: &Store) -> Result<()>;
|
||||
|
||||
/// Add internal annotated link
|
||||
fn add_internal_annotated_link(&mut self, link: &mut Entry, annotation: String) -> Result<()>;
|
||||
}
|
||||
|
@ -452,6 +456,17 @@ impl InternalLinker for Entry {
|
|||
})
|
||||
}
|
||||
|
||||
fn unlink(&mut self, store: &Store) -> Result<()> {
|
||||
for id in self.get_internal_links()?.map(|l| l.get_store_id().clone()) {
|
||||
match store.get(id).map_err(LE::from)? {
|
||||
Some(mut entry) => self.remove_internal_link(&mut entry)?,
|
||||
None => return Err(LEK::LinkTargetDoesNotExist.into()),
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_internal_annotated_link(&mut self, link: &mut Entry, annotation: String) -> Result<()> {
|
||||
let new_link = Link::Annotated {
|
||||
link: link.get_location().clone(),
|
||||
|
|
Loading…
Reference in a new issue