From 8912939e299bc915e88b62bc2df6cfd666035244 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 26 Jun 2019 19:57:08 +0200 Subject: [PATCH] libimagentrylink: Add debugging output Signed-off-by: Matthias Beyer --- lib/entry/libimagentrylink/src/link.rs | 2 ++ lib/entry/libimagentrylink/src/linkable.rs | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/entry/libimagentrylink/src/link.rs b/lib/entry/libimagentrylink/src/link.rs index b60e22ca..f12698be 100644 --- a/lib/entry/libimagentrylink/src/link.rs +++ b/lib/entry/libimagentrylink/src/link.rs @@ -73,6 +73,7 @@ impl Link { } pub(crate) fn to_value(&self) -> Result { + debug!("Converting {:?} to Value", self); match self { Link::Id { ref link } => link, Link::LinkTo { ref link } => link, @@ -88,6 +89,7 @@ impl Link { impl ::std::cmp::PartialEq for Link { fn eq(&self, other: &Self) -> bool { + debug!("Checking for equality: {:?} == {:?}", self, other); match (self, other) { (&Link::Id { link: ref a }, &Link::Id { link: ref b }) => a.eq(&b), (&Link::LinkTo { link: ref a }, &Link::LinkTo { link: ref b })=> a.eq(&b), diff --git a/lib/entry/libimagentrylink/src/linkable.rs b/lib/entry/libimagentrylink/src/linkable.rs index 2c07af4b..2deddd88 100644 --- a/lib/entry/libimagentrylink/src/linkable.rs +++ b/lib/entry/libimagentrylink/src/linkable.rs @@ -112,6 +112,7 @@ impl Linkable for Entry { /// Get all links which are unidirectional links fn unidirectional_links(&self) -> Result { + debug!("Getting unidirectional links"); trace!("Getting unidirectional links from header of '{}' = {:?}", self.get_location(), self.get_header()); let iter = self.get_header() @@ -126,6 +127,7 @@ impl Linkable for Entry { /// Get all links which are directional links, outgoing fn directional_links_to(&self) -> Result { + debug!("Getting directional links (to)"); trace!("Getting unidirectional (to) links from header of '{}' = {:?}", self.get_location(), self.get_header()); let iter = self.get_header() @@ -140,6 +142,7 @@ impl Linkable for Entry { /// Get all links which are directional links, incoming fn directional_links_from(&self) -> Result { + debug!("Getting directional links (from)"); trace!("Getting unidirectional (from) links from header of '{}' = {:?}", self.get_location(), self.get_header()); let iter = self.get_header() @@ -159,13 +162,17 @@ impl Linkable for Entry { alter_linking(self, other, |mut left, mut right| { let mut left_internal = left.internal.unwrap_or_else(|| vec![]); + trace!("left: {:?} <- {:?}", left_internal, right_location); left_internal.push(right_location); + trace!("left: {:?}", left_internal); left_internal.sort_unstable(); left_internal.dedup(); let mut right_internal = right.internal.unwrap_or_else(|| vec![]); + trace!("right: {:?} <- {:?}", right_internal, left_location); right_internal.push(left_location); + trace!("right: {:?}", right_internal); right_internal.sort_unstable(); right_internal.dedup(); @@ -173,6 +180,7 @@ impl Linkable for Entry { left.internal = Some(left_internal); right.internal = Some(right_internal); + trace!("Finished: ({:?}, {:?})", left, right); Ok((left, right)) }) } @@ -184,13 +192,17 @@ impl Linkable for Entry { alter_linking(self, other, |mut left, mut right| { let mut left_internal = left.internal.unwrap_or_else(|| vec![]); + trace!("left: {:?} retaining {:?}", left_internal, right_location); left_internal.retain(|l| *l != right_location); + trace!("left: {:?}", left_internal); left_internal.sort_unstable(); left_internal.dedup(); let mut right_internal = right.internal.unwrap_or_else(|| vec![]); + trace!("right: {:?} retaining {:?}", right_internal, left_location); right_internal.retain(|l| *l != left_location); + trace!("right: {:?}", right_internal); right_internal.sort_unstable(); right_internal.dedup(); @@ -198,11 +210,13 @@ impl Linkable for Entry { left.internal = Some(left_internal); right.internal = Some(right_internal); + trace!("Finished: ({:?}, {:?})", left, right); Ok((left, right)) }) } fn unlink(&mut self, store: &Store) -> Result<()> { + debug!("Unlinking {:?}", self); for id in self.links()?.map(|l| l.get_store_id().clone()) { match store.get(id).context("Failed to get entry")? { Some(mut entry) => self.remove_link(&mut entry)?, @@ -219,14 +233,19 @@ impl Linkable for Entry { alter_linking(self, other, |mut left, mut right| { let mut left_to = left.to.unwrap_or_else(|| vec![]); + trace!("left_to: {:?} <- {:?}", left_to, right_location); left_to.push(right_location); + trace!("left_to: {:?}", left_to); let mut right_from = right.from.unwrap_or_else(|| vec![]); + trace!("right_from: {:?} <- {:?}", right_from, left_location); right_from.push(left_location); + trace!("right_from: {:?}", right_from); left.to = Some(left_to); right.from = Some(right_from); + trace!("Finished: ({:?}, {:?})", left, right); Ok((left, right)) }) } @@ -238,14 +257,19 @@ impl Linkable for Entry { alter_linking(self, other, |mut left, mut right| { let mut left_to = left.to.unwrap_or_else(|| vec![]); + trace!("left_to: {:?} retaining {:?}", left_to, right_location); left_to.retain(|l| *l != right_location); + trace!("left_to: {:?}", left_to); let mut right_from = right.from.unwrap_or_else(|| vec![]); + trace!("right_from: {:?} retaining {:?}", right_from, left_location); right_from.retain(|l| *l != left_location); + trace!("right_from: {:?}", right_from); left.to = Some(left_to); right.from = Some(right_from); + trace!("Finished: ({:?}, {:?})", left, right); Ok((left, right)) }) }