From 617cb97ddfab49229e67238c3c7da3cf79b3dc9a Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 30 Jun 2016 11:10:38 +0200 Subject: [PATCH] Add Ref::get_path_hash() --- libimagref/src/reference.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libimagref/src/reference.rs b/libimagref/src/reference.rs index e1ed79b9..8bdbbb6f 100644 --- a/libimagref/src/reference.rs +++ b/libimagref/src/reference.rs @@ -211,6 +211,17 @@ impl<'a> Ref<'a> { } } + /// Get the hash from the path of the ref + pub fn get_path_hash(&self) -> Option { + self.0 + .get_location() + .as_path() + .file_name() + .and_then(|osstr| osstr.to_str()) + .and_then(|s| s.split("~").next()) + .map(String::from) + } + /// Get the hash of the link target which is stored in the ref object pub fn get_stored_hash(&self) -> Result { match self.0.get_header().read("ref.content_hash") {