diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-06-21 22:30:53 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-07-04 19:29:02 +0200 |
commit | 130ea0db1381c6c0ae12f11c4f4fb53d72937cfa (patch) | |
tree | 97f18ed54fb281fefdf9319681d9f2bdfabe731b /libimagref | |
parent | 4ccbb174fa0b4ee95b91c343c8953c95f3601cf6 (diff) |
Impl Ref::hash_path() (changes returntype)
Diffstat (limited to 'libimagref')
-rw-r--r-- | libimagref/src/reference.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libimagref/src/reference.rs b/libimagref/src/reference.rs index 602708ff..084464b8 100644 --- a/libimagref/src/reference.rs +++ b/libimagref/src/reference.rs @@ -178,8 +178,19 @@ impl<'a> Ref<'a> { /// Creates a Hash from a PathBuf by making the PathBuf absolute and then running a hash /// algorithm on it - fn hash_path(pb: &PathBuf) -> String { - unimplemented!() + fn hash_path(pb: &PathBuf) -> Result<String> { + use std::io::Read; + use crypto::sha1::Sha1; + use crypto::digest::Digest; + + match pb.to_str() { + Some(s) => { + let mut hasher = Sha1::new(); + hasher.input_str(s); + Ok(hasher.result_str()) + }, + None => return Err(REK::PathUTF8Error.into_error()), + } } /// check whether the pointer the Ref represents still points to a file which exists |