diff --git a/lib/entry/libimagentrycategory/src/lib.rs b/lib/entry/libimagentrycategory/src/lib.rs index 822489b5..58c72d39 100644 --- a/lib/entry/libimagentrycategory/src/lib.rs +++ b/lib/entry/libimagentrycategory/src/lib.rs @@ -50,7 +50,7 @@ extern crate libimagstore; pub mod category; pub mod entry; pub mod error; -pub mod register; +pub mod store; module_entry_path_mod!("category"); diff --git a/lib/entry/libimagentrycategory/src/register.rs b/lib/entry/libimagentrycategory/src/store.rs similarity index 87% rename from lib/entry/libimagentrycategory/src/register.rs rename to lib/entry/libimagentrycategory/src/store.rs index aa75ab4f..6d41a134 100644 --- a/lib/entry/libimagentrycategory/src/register.rs +++ b/lib/entry/libimagentrycategory/src/store.rs @@ -39,7 +39,7 @@ pub const CATEGORY_REGISTER_NAME_FIELD_PATH : &'static str = "category.register. /// Extension on the Store to make it a register for categories /// /// The register writes files to the -pub trait CategoryRegister { +pub trait CategoryStore { fn category_exists(&self, name: &str) -> Result; @@ -53,7 +53,7 @@ pub trait CategoryRegister { } -impl CategoryRegister for Store { +impl CategoryStore for Store { /// Check whether a category exists fn category_exists(&self, name: &str) -> Result { @@ -64,39 +64,23 @@ impl CategoryRegister for Store { /// Create a category /// /// Fails if the category already exists (returns false then) - fn create_category(&self, name: &str) -> Result { - use libimagstore::error::StoreErrorKind as SEK; + fn create_category(&self, name: &str) -> Result> { + let sid = mk_category_storeid(self.path().clone(), name)?; + let mut entry = self.create(sid)?; - let sid = mk_category_storeid(self.path().clone(), name)?; + entry.set_isflag::()?; + let _ = entry + .get_header_mut() + .insert(CATEGORY_REGISTER_NAME_FIELD_PATH, Value::String(String::from(name)))?; - match self.create(sid) { - Ok(mut entry) => { - let val = Value::String(String::from(name)); - entry.get_header_mut() - .insert(CATEGORY_REGISTER_NAME_FIELD_PATH, val) - .map(|opt| if opt.is_none() { - debug!("Setting category header worked") - } else { - warn!("Setting category header replaced existing value: {:?}", opt); - }) - .map(|_| true) - .chain_err(|| CEK::HeaderWriteError) - .chain_err(|| CEK::StoreWriteError) - } - Err(store_error) => if is_match!(store_error.kind(), &SEK::EntryAlreadyExists(_)) { - Ok(false) - } else { - Err(store_error).chain_err(|| CEK::StoreWriteError) - } - } + Ok(entry) } /// Delete a category fn delete_category(&self, name: &str) -> Result<()> { let sid = mk_category_storeid(self.path().clone(), name)?; - - self.delete(sid).chain_err(|| CEK::StoreWriteError) + self.delete(sid).map_err(CE::from) } /// Get all category names