Raise error when reading links failed, rather than assuming 1

This commit is contained in:
Matthias Beyer 2016-10-17 13:43:45 +02:00
parent 44f78ae50a
commit dd4f0c7586

View file

@ -32,6 +32,7 @@ use libimagentrylink::internal::InternalLinker;
mod error { mod error {
generate_error_imports!(); generate_error_imports!();
generate_error_types!(NoLinksLeftCheckerHookError, NoLinksLeftCheckerHookErrorKind, generate_error_types!(NoLinksLeftCheckerHookError, NoLinksLeftCheckerHookErrorKind,
ReadInternalLinksError => "Error while reading internal links of entry",
LinksLeft => "The entry has links and therefor cannot be deleted." LinksLeft => "The entry has links and therefor cannot be deleted."
); );
} }
@ -86,21 +87,17 @@ impl HookDataAccessorProvider for DenyDeletionOfLinkedEntriesHook {
impl NonMutableHookDataAccessor for DenyDeletionOfLinkedEntriesHook { impl NonMutableHookDataAccessor for DenyDeletionOfLinkedEntriesHook {
fn access(&self, fle: &FileLockEntry) -> HookResult<()> { fn access(&self, fle: &FileLockEntry) -> HookResult<()> {
use libimagutil::warn_result::*;
use libimagutil::debug_result::*;
use libimagerror::trace::MapErrTrace;
use libimagerror::into::IntoError; use libimagerror::into::IntoError;
use self::error::MapErrInto;
debug!("[NO LINKS LEFT CHECKER HOOK] {:?}", fle.get_location()); debug!("[NO LINKS LEFT CHECKER HOOK] {:?}", fle.get_location());
let n = fle let n = try!(fle
.get_internal_links() .get_internal_links()
.map(|i| i.count()) .map(|i| i.count())
.map_warn_err_str("[NO LINKS LEFT CHECKER HOOK]: Cannot get internal links") .map_err_into(NLLCHEK::ReadInternalLinksError)
.map_warn_err_str("[NO LINKS LEFT CHECKER HOOK]: Assuming 1 to automatically abort") .map_err(Box::new)
.map_dbg_err_str("[NO LINKS LEFT CHECKER HOOK]: Printing trace now") .map_err(|e| HEK::HookExecutionError.into_error_with_cause(e)));
.map_err_trace()
.unwrap_or(1);
if n > 0 { if n > 0 {
Err(NLLCHEK::LinksLeft.into_error()) Err(NLLCHEK::LinksLeft.into_error())