1
Fork 0

kmc-solid: Handle errors returned by SOLID_FS_ReadDir

This commit is contained in:
Tomoaki Kawada 2022-10-13 14:16:12 +09:00
parent 2a9217601c
commit 76bec177bc

View file

@ -175,15 +175,19 @@ impl Iterator for ReadDir {
type Item = io::Result<DirEntry>; type Item = io::Result<DirEntry>;
fn next(&mut self) -> Option<io::Result<DirEntry>> { fn next(&mut self) -> Option<io::Result<DirEntry>> {
unsafe { let entry = unsafe {
let mut out_dirent = MaybeUninit::uninit(); let mut out_entry = MaybeUninit::uninit();
error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir( match error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
self.inner.dirp, self.inner.dirp,
out_dirent.as_mut_ptr(), out_entry.as_mut_ptr(),
)) )) {
.ok()?; Ok(_) => out_entry.assume_init(),
Some(Ok(DirEntry { entry: out_dirent.assume_init(), inner: Arc::clone(&self.inner) })) Err(e) if e.as_raw() == abi::SOLID_ERR_NOTFOUND => return None,
Err(e) => return Some(Err(e.as_io_error())),
} }
};
(entry.d_name[0] != 0).then(|| Ok(DirEntry { entry, inner: Arc::clone(&self.inner) }))
} }
} }