summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-19 22:18:36 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-20 14:43:21 +0100
commit0a625481731dd3e4446d61b1c12230dcc50e50d1 (patch)
tree91471511735985c999a45545e9b82f42cf074d58
parent37bf2ce191636e0e962694290b8ea8e87f23cb8e (diff)
Add function to get relative file path
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/entry/libimagentryref/src/reference.rs26
1 files changed, 23 insertions, 3 deletions
diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs
index 9815f4e..e3ea91e 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<bool>;
- /// Get the stored hash.
- fn get_path(&self) -> Result<PathBuf>;
+ fn get_path(&self, config: &Config) -> Result<PathBuf>;
+
+ fn get_relative_path(&self) -> Result<PathBuf>;
/// 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<PathBuf> {
+ /// Get the path of the actual file
+ fn get_path(&self, config: &Config) -> Result<PathBuf> {
+ 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<PathBuf> {
self.0
.get_header()
.read("ref.relpath")