diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-09-05 14:21:56 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-09-05 16:15:40 +0200 |
commit | 5399b8ca7bf6f478c56c815b23b2be9833a73505 (patch) | |
tree | 160207489d1377f6a23b090b4c39b2c82c6d6028 /libimagref | |
parent | a6ca041903aef5b3c91dab00797a2f25a28eab68 (diff) |
Add variant of Ref::update_ref() to update with custom Hasher instance
Diffstat (limited to 'libimagref')
-rw-r--r-- | libimagref/src/reference.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/libimagref/src/reference.rs b/libimagref/src/reference.rs index 571312bf..e1d0f02a 100644 --- a/libimagref/src/reference.rs +++ b/libimagref/src/reference.rs @@ -353,6 +353,12 @@ impl<'a> Ref<'a> { /// Update the Ref by re-checking the file from FS /// This errors if the file is not present or cannot be read() pub fn update_ref(&mut self) -> Result<()> { + self.update_ref_with_hasher(&DefaultHasher::new()) + } + + /// Update the Ref by re-checking the file from FS using the passed Hasher instance + /// This errors if the file is not present or cannot be read() + pub fn update_ref_with_hasher<H: Hasher>(&mut self, h: &H) -> Result<()> { let current_hash = try!(self.get_current_hash()); // uses the default hasher let current_perm = try!(self.get_current_permissions()); @@ -363,11 +369,9 @@ impl<'a> Ref<'a> { .map_err(|e| REK::StoreWriteError.into_error_with_cause(e)) ); - let hasher_name = DefaultHasher::new().hash_name(); - try!(self.0 .get_header_mut() - .set(&format!("ref.content_hash.{}", hasher_name)[..], Value::String(current_hash)) + .set(&format!("ref.content_hash.{}", h.hash_name())[..], Value::String(current_hash)) .map_err(Box::new) .map_err(|e| REK::StoreWriteError.into_error_with_cause(e)) ); |