From 7fb13acf15f5ebfc77148eee2d26de3d4196fcba Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 8 Jan 2018 23:34:13 +0100 Subject: [PATCH] Add Ref::is_ref() --- lib/entry/libimagentryref/Cargo.toml | 1 + lib/entry/libimagentryref/src/error.rs | 1 + lib/entry/libimagentryref/src/lib.rs | 1 + lib/entry/libimagentryref/src/reference.rs | 11 +++++++++++ lib/entry/libimagentryref/src/refstore.rs | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/lib/entry/libimagentryref/Cargo.toml b/lib/entry/libimagentryref/Cargo.toml index 4a791e4a..3060bf1f 100644 --- a/lib/entry/libimagentryref/Cargo.toml +++ b/lib/entry/libimagentryref/Cargo.toml @@ -31,3 +31,4 @@ walkdir = "1" libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.6.0", path = "../../../lib/core/libimagerror" } libimagentrylist = { version = "0.6.0", path = "../../../lib/entry/libimagentrylist" } +libimagentryutil = { version = "0.6.0", path = "../../../lib/entry/libimagentryutil" } diff --git a/lib/entry/libimagentryref/src/error.rs b/lib/entry/libimagentryref/src/error.rs index f519b8c5..e2159f63 100644 --- a/lib/entry/libimagentryref/src/error.rs +++ b/lib/entry/libimagentryref/src/error.rs @@ -26,6 +26,7 @@ error_chain! { ListError(::libimagentrylist::error::ListError, ::libimagentrylist::error::ListErrorKind); StoreError(::libimagstore::error::StoreError, ::libimagstore::error::StoreErrorKind); TomlQueryError(::toml_query::error::Error, ::toml_query::error::ErrorKind); + EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind); } foreign_links { diff --git a/lib/entry/libimagentryref/src/lib.rs b/lib/entry/libimagentryref/src/lib.rs index 2ef25567..ea4305d3 100644 --- a/lib/entry/libimagentryref/src/lib.rs +++ b/lib/entry/libimagentryref/src/lib.rs @@ -45,6 +45,7 @@ extern crate walkdir; #[macro_use] extern crate libimagstore; extern crate libimagerror; extern crate libimagentrylist; +#[macro_use] extern crate libimagentryutil; #[macro_use] extern crate error_chain; module_entry_path_mod!("ref"); diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index 9c20011b..78c9d44f 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -25,6 +25,8 @@ use std::fs::File; use std::fs::Permissions; use libimagstore::store::Entry; +use libimagentryutil::isa::Is; +use libimagentryutil::isa::IsKindHeaderPathProvider; use toml::Value; use toml_query::read::TomlValueReadExt; @@ -38,6 +40,9 @@ use hasher::*; pub trait Ref { + /// Check whether the underlying object is actually a ref + fn is_ref(&self) -> Result; + /// Get the hash from the path of the ref fn get_path_hash(&self) -> Result; @@ -113,9 +118,15 @@ pub trait Ref { fn get_current_permissions(&self) -> Result; } +provide_kindflag_path!(pub IsRef, "ref.is_ref"); impl Ref for Entry { + /// Check whether the underlying object is actually a ref + fn is_ref(&self) -> Result { + self.is::().map_err(From::from) + } + /// Get the hash from the path of the ref fn get_path_hash(&self) -> Result { self.get_location() diff --git a/lib/entry/libimagentryref/src/refstore.rs b/lib/entry/libimagentryref/src/refstore.rs index 8a7413b4..5d8fc489 100644 --- a/lib/entry/libimagentryref/src/refstore.rs +++ b/lib/entry/libimagentryref/src/refstore.rs @@ -26,6 +26,7 @@ use libimagstore::storeid::IntoStoreId; use libimagstore::storeid::StoreId; use libimagstore::storeid::StoreIdIterator; use libimagstore::store::Store; +use libimagentryutil::isa::Is; use toml::Value; @@ -34,6 +35,7 @@ use error::RefError as RE; use error::ResultExt; use error::Result; use flags::RefFlags; +use reference::IsRef; use hasher::*; use module_path::ModuleEntryPath; use util::*; @@ -282,6 +284,8 @@ impl RefStore for Store { } } + let _ = fle.set_isflag::()?; + Ok(fle) }