style: switch from try! to ?

This commit is contained in:
Andrew Gallant 2017-10-20 22:35:59 -04:00
parent 2b4e508c75
commit 5ce6b10716

View File

@ -821,22 +821,21 @@ impl IntoIter {
} }
fn follow(&self, mut dent: DirEntry) -> Result<DirEntry> { fn follow(&self, mut dent: DirEntry) -> Result<DirEntry> {
dent = try!(DirEntry::from_link(self.depth, dent = DirEntry::from_link(self.depth, dent.path().to_path_buf())?;
dent.path().to_path_buf()));
// The only way a symlink can cause a loop is if it points // The only way a symlink can cause a loop is if it points
// to a directory. Otherwise, it always points to a leaf // to a directory. Otherwise, it always points to a leaf
// and we can omit any loop checks. // and we can omit any loop checks.
if dent.file_type().is_dir() { if dent.file_type().is_dir() {
try!(self.check_loop(dent.path())); self.check_loop(dent.path())?;
} }
Ok(dent) Ok(dent)
} }
fn check_loop<P: AsRef<Path>>(&self, child: P) -> Result<()> { fn check_loop<P: AsRef<Path>>(&self, child: P) -> Result<()> {
for ancestor in self.stack_path.iter().rev() { for ancestor in self.stack_path.iter().rev() {
let same = try!(is_same_file(ancestor, &child).map_err(|err| { let same = is_same_file(ancestor, &child).map_err(|err| {
Error::from_io(self.depth, err) Error::from_io(self.depth, err)
})); })?;
if same { if same {
return Err(Error { return Err(Error {
depth: self.depth, depth: self.depth,
@ -976,9 +975,9 @@ impl DirEntry {
#[cfg(not(unix))] #[cfg(not(unix))]
fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> { fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> {
let ty = try!(ent.file_type().map_err(|err| { let ty = ent.file_type().map_err(|err| {
Error::from_path(depth, ent.path(), err) Error::from_path(depth, ent.path(), err)
})); })?;
Ok(DirEntry { Ok(DirEntry {
path: ent.path(), path: ent.path(),
ty: ty, ty: ty,
@ -991,9 +990,9 @@ impl DirEntry {
fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> { fn from_entry(depth: usize, ent: &fs::DirEntry) -> Result<DirEntry> {
use std::os::unix::fs::DirEntryExt; use std::os::unix::fs::DirEntryExt;
let ty = try!(ent.file_type().map_err(|err| { let ty = ent.file_type().map_err(|err| {
Error::from_path(depth, ent.path(), err) Error::from_path(depth, ent.path(), err)
})); })?;
Ok(DirEntry { Ok(DirEntry {
path: ent.path(), path: ent.path(),
ty: ty, ty: ty,
@ -1005,9 +1004,9 @@ impl DirEntry {
#[cfg(not(unix))] #[cfg(not(unix))]
fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> { fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> {
let md = try!(fs::metadata(&pb).map_err(|err| { let md = fs::metadata(&pb).map_err(|err| {
Error::from_path(depth, pb.clone(), err) Error::from_path(depth, pb.clone(), err)
})); })?;
Ok(DirEntry { Ok(DirEntry {
path: pb, path: pb,
ty: md.file_type(), ty: md.file_type(),
@ -1020,9 +1019,9 @@ impl DirEntry {
fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> { fn from_link(depth: usize, pb: PathBuf) -> Result<DirEntry> {
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
let md = try!(fs::metadata(&pb).map_err(|err| { let md = fs::metadata(&pb).map_err(|err| {
Error::from_path(depth, pb.clone(), err) Error::from_path(depth, pb.clone(), err)
})); })?;
Ok(DirEntry { Ok(DirEntry {
path: pb, path: pb,
ty: md.file_type(), ty: md.file_type(),