From f321aa82a1dd69940a539deadf0f4ef3ed2a05ae Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 26 Apr 2018 11:20:09 +0200 Subject: [PATCH] Make sure category is linked when setting it --- lib/entry/libimagentrycategory/src/category.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/entry/libimagentrycategory/src/category.rs b/lib/entry/libimagentrycategory/src/category.rs index cd0e09ac..a9abe76c 100644 --- a/lib/entry/libimagentrycategory/src/category.rs +++ b/lib/entry/libimagentrycategory/src/category.rs @@ -72,12 +72,15 @@ impl EntryCategory for Entry { /// /// This function should be used by default over EntryCategory::set_category()! fn set_category_checked(&mut self, register: &CategoryRegister, s: Category) -> Result<()> { - register.category_exists(&s.0) - .and_then(|bl| if bl { - self.set_category(s) - } else { - Err(CE::from_kind(CEK::CategoryDoesNotExist)) - }) + let c_str = s.clone().into(); + let mut category = register + .get_category_by_name(&c_str)? + .ok_or_else(|| CE::from_kind(CEK::CategoryDoesNotExist))?; + + let _ = self.set_category(s)?; + let _ = self.add_internal_link(&mut category)?; + + Ok(()) } fn get_category(&self) -> Result> {