Remove InternalLinker::set_internal_links()
This function needs to be removed because of the following problem: When linking from one entry to another, and then removing the link in the first entry with ::set_internal_links(vec![]), we end up with a dangling link in the second entry, because the ::set_internal_links() function does not take care of removing the links in the "other" entries. Actually, it is not even able to do so, because it would need to `Store::get()` those entries, but it does not have access to the store. Adding a `store` parameter to the function would be possible, but only increase its complexity unnecessarily. This is why I opt for removing this function (which is btw not used once in the whole imag codebase). Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
85f8082cbe
commit
5a250bd991
1 changed files with 0 additions and 35 deletions
|
@ -162,9 +162,6 @@ pub trait InternalLinker {
|
|||
/// Get the internal links from the implementor object
|
||||
fn get_internal_links(&self) -> Result<LinkIter>;
|
||||
|
||||
/// Set the internal links for the implementor object
|
||||
fn set_internal_links(&mut self, links: Vec<&mut Entry>) -> Result<LinkIter>;
|
||||
|
||||
/// Add an internal link to the implementor object
|
||||
fn add_internal_link(&mut self, link: &mut Entry) -> Result<()>;
|
||||
|
||||
|
@ -273,38 +270,6 @@ impl InternalLinker for Entry {
|
|||
process_rw_result(res)
|
||||
}
|
||||
|
||||
/// Set the links in a header and return the old links, if any.
|
||||
fn set_internal_links(&mut self, links: Vec<&mut Entry>) -> Result<LinkIter> {
|
||||
debug!("Setting internal links");
|
||||
|
||||
let self_location = self.get_location().clone();
|
||||
let mut new_links = vec![];
|
||||
|
||||
for link in links {
|
||||
if let Err(e) = add_foreign_link(link, self_location.clone()) {
|
||||
return Err(e);
|
||||
}
|
||||
new_links.push(link.get_location().clone().into());
|
||||
}
|
||||
|
||||
let new_links = LinkIter::new(new_links)
|
||||
.into_values()
|
||||
.into_iter()
|
||||
.fold(Ok(vec![]), |acc: Result<Vec<_>>, elem| {
|
||||
acc.and_then(move |mut v| {
|
||||
v.push(elem.context(EM::ConversionError)?);
|
||||
Ok(v)
|
||||
})
|
||||
})?;
|
||||
let res = self
|
||||
.get_header_mut()
|
||||
.insert("links.internal", Value::Array(new_links))
|
||||
.context(format_err!("Failed to insert header 'links.internal' of '{}'", self.get_location()))
|
||||
.context(EM::EntryHeaderReadError)
|
||||
.map_err(Error::from);
|
||||
process_rw_result(res)
|
||||
}
|
||||
|
||||
fn add_internal_link(&mut self, link: &mut Entry) -> Result<()> {
|
||||
debug!("Adding internal link: {:?}", link);
|
||||
let location = link.get_location().clone().into();
|
||||
|
|
Loading…
Reference in a new issue