From 078936191b5e39ba576d3ab2a742c0a85958d60e Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 30 Oct 2017 20:17:22 +0100 Subject: [PATCH] Replace uses of try!() macro with "?" operator --- lib/entry/libimagentryref/src/flags.rs | 4 ++-- lib/entry/libimagentryref/src/hasher.rs | 2 +- .../libimagentryref/src/hashers/nbytes.rs | 4 ++-- lib/entry/libimagentryref/src/lister.rs | 2 +- lib/entry/libimagentryref/src/reference.rs | 16 ++++++------- lib/entry/libimagentryref/src/refstore.rs | 23 ++++++++----------- 6 files changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/entry/libimagentryref/src/flags.rs b/lib/entry/libimagentryref/src/flags.rs index a15a97ce..2d87c7c0 100644 --- a/lib/entry/libimagentryref/src/flags.rs +++ b/lib/entry/libimagentryref/src/flags.rs @@ -49,8 +49,8 @@ impl RefFlags { } Ok(RefFlags { - content_hashing: try!(get_field(v, "ref.flags.content_hashing")), - permission_tracking: try!(get_field(v, "ref.flags.permission_tracking")), + content_hashing: get_field(v, "ref.flags.content_hashing")?, + permission_tracking: get_field(v, "ref.flags.permission_tracking")?, }) } diff --git a/lib/entry/libimagentryref/src/hasher.rs b/lib/entry/libimagentryref/src/hasher.rs index d50c08ce..79088c2b 100644 --- a/lib/entry/libimagentryref/src/hasher.rs +++ b/lib/entry/libimagentryref/src/hasher.rs @@ -55,7 +55,7 @@ impl Hasher for DefaultHasher { fn create_hash(&mut self, _: &PathBuf, c: &mut R) -> Result { let mut s = String::new(); - try!(c.read_to_string(&mut s)); + c.read_to_string(&mut s)?; self.hasher.input_str(&s[..]); Ok(self.hasher.result_str()) } diff --git a/lib/entry/libimagentryref/src/hashers/nbytes.rs b/lib/entry/libimagentryref/src/hashers/nbytes.rs index de2e311e..dd910042 100644 --- a/lib/entry/libimagentryref/src/hashers/nbytes.rs +++ b/lib/entry/libimagentryref/src/hashers/nbytes.rs @@ -51,12 +51,12 @@ impl Hasher for NBytesHasher { } fn create_hash(&mut self, _: &PathBuf, contents: &mut R) -> Result { - let s : String = try!(contents + let s : String = contents .bytes() .take(self.n) .collect::, _>>() .map_err(From::from) - .and_then(|v| String::from_utf8(v).map_err(RE::from))); + .and_then(|v| String::from_utf8(v).map_err(RE::from))?; self.hasher.input_str(&s[..]); Ok(self.hasher.result_str()) diff --git a/lib/entry/libimagentryref/src/lister.rs b/lib/entry/libimagentryref/src/lister.rs index 0cf4d5bc..e3d9bdfa 100644 --- a/lib/entry/libimagentryref/src/lister.rs +++ b/lib/entry/libimagentryref/src/lister.rs @@ -89,7 +89,7 @@ impl Lister for RefLister { debug!("Listing Entry: {:?}", entry); { let is_dead = if self.check_dead { - if try!(lerror::ResultExt::chain_err(entry.fs_link_exists(), || LEK::FormatError)) { + if lerror::ResultExt::chain_err(entry.fs_link_exists(), || LEK::FormatError)? { "dead" } else { "alive" diff --git a/lib/entry/libimagentryref/src/reference.rs b/lib/entry/libimagentryref/src/reference.rs index 3643dab0..c043b1e0 100644 --- a/lib/entry/libimagentryref/src/reference.rs +++ b/lib/entry/libimagentryref/src/reference.rs @@ -219,8 +219,8 @@ impl Ref for Entry { /// Check whether the Hashsum of the referenced file is equal to the stored hashsum fn fs_link_valid_hash(&self) -> Result { - let stored_hash = try!(self.get_stored_hash()); - let current_hash = try!(self.get_current_hash()); + let stored_hash = self.get_stored_hash()?; + let current_hash = self.get_current_hash()?; Ok(stored_hash == current_hash) } @@ -233,18 +233,18 @@ impl Ref for Entry { /// 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() fn update_ref_with_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()); + let current_hash = self.get_current_hash()?; // uses the default hasher + let current_perm = self.get_current_permissions()?; - try!(self + self .get_header_mut() .set("ref.permissions.ro", Value::Boolean(current_perm.readonly())) - ); + ?; - try!(self + self .get_header_mut() .set(&format!("ref.content_hash.{}", h.hash_name())[..], Value::String(current_hash)) - ); + ?; Ok(()) } diff --git a/lib/entry/libimagentryref/src/refstore.rs b/lib/entry/libimagentryref/src/refstore.rs index 102d3d94..8a7413b4 100644 --- a/lib/entry/libimagentryref/src/refstore.rs +++ b/lib/entry/libimagentryref/src/refstore.rs @@ -91,10 +91,10 @@ impl RefStore for Store { // manually here. If you can come up with a better version of this, feel free to // take this note as a todo. for r in possible_refs { - let contains_hash = try!(r.to_str() + let contains_hash = r.to_str() .chain_err(|| REK::TypeConversionError) .map(|s| s.contains(&hash[..])) - ); + ?; if !contains_hash { continue; @@ -182,14 +182,14 @@ impl RefStore for Store { } let (mut fle, content_hash, permissions, canonical_path) = { // scope to be able to fold - try!(File::open(pb.clone()) + File::open(pb.clone()) .chain_err(|| REK::RefTargetFileCannotBeOpened) // If we were able to open this file, // we hash the contents of the file and return (file, hash) .and_then(|mut file| { let opt_contenthash = if flags.get_content_hashing() { - Some(try!(h.create_hash(&pb, &mut file))) + Some(h.create_hash(&pb, &mut file)?) } else { None }; @@ -201,11 +201,9 @@ impl RefStore for Store { // and return (file, content hash, permissions) .and_then(|(file, opt_contenthash)| { let opt_permissions = if flags.get_permission_tracking() { - Some(try!(file - .metadata() - .map(|md| md.permissions()) - .chain_err(|| REK::RefTargetCannotReadPermissions) - )) + Some(file.metadata() + .map(|md| md.permissions()) + .chain_err(|| REK::RefTargetCannotReadPermissions)?) } else { None }; @@ -226,7 +224,7 @@ impl RefStore for Store { // and then we hash the canonicalized path // and return (file, content hash, permissions, canonicalized path, path hash) .and_then(|(opt_contenthash, opt_permissions, can)| { - let path_hash = try!(hash_path(&can).chain_err(|| REK::PathHashingError)); + let path_hash = hash_path(&can).chain_err(|| REK::PathHashingError)?; Ok((opt_contenthash, opt_permissions, can, path_hash)) }) @@ -246,10 +244,9 @@ impl RefStore for Store { // and then we create the FileLockEntry in the Store // and return (filelockentry, content hash, permissions, canonicalized path) .and_then(|(opt_conhash, opt_perm, can, path_hash)| { - let fle = try!(self.create(ModuleEntryPath::new(path_hash))); + let fle = self.create(ModuleEntryPath::new(path_hash))?; Ok((fle, opt_conhash, opt_perm, can)) - }) - ) + })? }; for tpl in [