From 5a250bd991bae2721e74dbcc30970c7ac25ec61f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 18 May 2019 02:17:56 +0200 Subject: [PATCH] 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 --- lib/entry/libimagentrylink/src/internal.rs | 35 ---------------------- 1 file changed, 35 deletions(-) diff --git a/lib/entry/libimagentrylink/src/internal.rs b/lib/entry/libimagentrylink/src/internal.rs index 224eac99..60836a46 100644 --- a/lib/entry/libimagentrylink/src/internal.rs +++ b/lib/entry/libimagentrylink/src/internal.rs @@ -162,9 +162,6 @@ pub trait InternalLinker { /// Get the internal links from the implementor object fn get_internal_links(&self) -> Result; - /// Set the internal links for the implementor object - fn set_internal_links(&mut self, links: Vec<&mut Entry>) -> Result; - /// 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 { - 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>, 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();