From cbb47cffcbb3d6cd2d238c587a8b3745ac5ed384 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 13 Feb 2018 22:37:22 +0100 Subject: Implement Ref functions --- lib/entry/libimagentryref/src/reference.rs | 37 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'lib/entry/libimagentryref') diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index 43222a86..b2828e28 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -42,7 +42,7 @@ pub trait Ref { /// Get the stored hash. /// /// Does not need a `UniqueRefPathGenerator` as it reads the hash stored in the header - fn get_hash(&self) -> Result; + fn get_hash(&self) -> Result<&str>; /// Get the referenced path. /// @@ -50,12 +50,7 @@ pub trait Ref { fn get_path(&self) -> Result; /// Check whether the referenced file still matches its hash - fn hash_valid(&self) -> Result; - - /// Update the stored hash - /// - /// This updates the hash in the header and moves the entry to the appropriate location - fn update_hash(&mut self, store: &Store) -> Result; + fn hash_valid(&self) -> RResult; /// Alias for `r.fs_link_exists() && r.deref().is_file()` fn is_ref_to_file(&self) -> Result { @@ -83,20 +78,30 @@ impl Ref for Entry { self.is::().map_err(From::from) } - fn get_hash(&self) -> Result { - unimplemented!() + fn get_hash(&self) -> Result<&str> { + self.get_header() + .read("ref.hash") + .map_err(RE::from)? + .ok_or_else(|| REK::HeaderFieldMissingError("ref.hash").into()) + .and_then(|v| v.as_str().ok_or_else(|| REK::HeaderTypeError("ref.hash", "string").into())) } fn get_path(&self) -> Result { - unimplemented!() - } - - fn hash_valid(&self) -> Result { - unimplemented!() + self.get_header() + .read("ref.path") + .map_err(RE::from)? + .ok_or_else(|| REK::HeaderFieldMissingError("ref.path").into()) + .and_then(|v| v.as_str().ok_or_else(|| REK::HeaderTypeError("ref.path", "string").into())) + .map(PathBuf::from) } - fn update_hash(&mut self, store: &Store) -> Result { - unimplemented!() + fn hash_valid(&self) -> RResult { + self.get_path() + .map(PathBuf::from) + .map_err(RE::from) + .map_err(RPG::Error::from) + .and_then(|pb| RPG::unique_hash(pb)) + .and_then(|h| Ok(h == self.get_hash()?)) } } -- cgit v1.2.3