Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
1401: cleanup: remove redundant unwrap in Dir::from_fd r=asomers a=scottlamb



Co-authored-by: Scott Lamb <slamb@slamb.org>
  • Loading branch information
bors[bot] and scottlamb committed Mar 24, 2021
2 parents 3f8a66d + 49ed986 commit 6af11c1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ impl Dir {

/// Converts from a file descriptor, closing it on success or failure.
pub fn from_fd(fd: RawFd) -> Result<Self> {
let d = unsafe { libc::fdopendir(fd) };
if d.is_null() {
let d = ptr::NonNull::new(unsafe { libc::fdopendir(fd) }).ok_or_else(|| {
let e = Error::last();
unsafe { libc::close(fd) };
return Err(e);
};
// Always guaranteed to be non-null by the previous check
Ok(Dir(ptr::NonNull::new(d).unwrap()))
e
})?;
Ok(Dir(d))
}

/// Returns an iterator of `Result<Entry>` which rewinds when finished.
Expand Down

0 comments on commit 6af11c1

Please sign in to comment.