Replace uses of try!() macro with "?" operator
This commit is contained in:
parent
81ceb50f4a
commit
078936191b
6 changed files with 24 additions and 27 deletions
|
@ -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")?,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ impl Hasher for DefaultHasher {
|
|||
|
||||
fn create_hash<R: Read>(&mut self, _: &PathBuf, c: &mut R) -> Result<String> {
|
||||
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())
|
||||
}
|
||||
|
|
|
@ -51,12 +51,12 @@ impl Hasher for NBytesHasher {
|
|||
}
|
||||
|
||||
fn create_hash<R: Read>(&mut self, _: &PathBuf, contents: &mut R) -> Result<String> {
|
||||
let s : String = try!(contents
|
||||
let s : String = contents
|
||||
.bytes()
|
||||
.take(self.n)
|
||||
.collect::<RResult<Vec<u8>, _>>()
|
||||
.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())
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<bool> {
|
||||
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<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());
|
||||
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(())
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
Some(file.metadata()
|
||||
.map(|md| md.permissions())
|
||||
.chain_err(|| REK::RefTargetCannotReadPermissions)
|
||||
))
|
||||
.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 [
|
||||
|
|
Loading…
Reference in a new issue