From 0a625481731dd3e4446d61b1c12230dcc50e50d1 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 19 Feb 2019 22:18:36 +0100 Subject: [PATCH] Add function to get relative file path Signed-off-by: Matthias Beyer --- lib/entry/libimagentryref/src/reference.rs | 26 +++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index 9815f4eb..e3ea91e7 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -138,8 +138,9 @@ pub trait Ref { /// Check whether the underlying object is actually a ref fn is_ref(&self) -> Result; - /// Get the stored hash. - fn get_path(&self) -> Result; + fn get_path(&self, config: &Config) -> Result; + + fn get_relative_path(&self) -> Result; /// Get the stored hash. fn get_hash(&self) -> Result<&str>; @@ -171,7 +172,26 @@ impl<'a, H: Hasher> Ref for RefWithHasher<'a, H> { }) } - fn get_path(&self) -> Result { + /// Get the path of the actual file + fn get_path(&self, config: &Config) -> Result { + use toml_query::read::TomlValueReadTypeExt; + + let relpath = self.0 + .get_header() + .read_string("ref.relpath")? + .map(PathBuf::from) + .ok_or_else(|| Error::from(EM::EntryHeaderFieldMissing("ref.relpath")))?; + + let collection_name = self.0 + .get_header() + .read_string("ref.collection")? + .ok_or_else(|| Error::from(EM::EntryHeaderFieldMissing("ref.collection")))?; + + get_file_path(config, &collection_name, relpath) + } + + /// Get the relative path, relative to the configured basepath + fn get_relative_path(&self) -> Result { self.0 .get_header() .read("ref.relpath")