Skip to content

Commit 76bec17

Browse files
committed
kmc-solid: Handle errors returned by SOLID_FS_ReadDir
1 parent 2a92176 commit 76bec17

File tree

1 file changed

+12
-8
lines changed
  • library/std/src/sys/solid

1 file changed

+12
-8
lines changed

library/std/src/sys/solid/fs.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,19 @@ impl Iterator for ReadDir {
175175
type Item = io::Result<DirEntry>;
176176

177177
fn next(&mut self) -> Option<io::Result<DirEntry>> {
178-
unsafe {
179-
let mut out_dirent = MaybeUninit::uninit();
180-
error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
178+
let entry = unsafe {
179+
let mut out_entry = MaybeUninit::uninit();
180+
match error::SolidError::err_if_negative(abi::SOLID_FS_ReadDir(
181181
self.inner.dirp,
182-
out_dirent.as_mut_ptr(),
183-
))
184-
.ok()?;
185-
Some(Ok(DirEntry { entry: out_dirent.assume_init(), inner: Arc::clone(&self.inner) }))
186-
}
182+
out_entry.as_mut_ptr(),
183+
)) {
184+
Ok(_) => out_entry.assume_init(),
185+
Err(e) if e.as_raw() == abi::SOLID_ERR_NOTFOUND => return None,
186+
Err(e) => return Some(Err(e.as_io_error())),
187+
}
188+
};
189+
190+
(entry.d_name[0] != 0).then(|| Ok(DirEntry { entry, inner: Arc::clone(&self.inner) }))
187191
}
188192
}
189193

0 commit comments

Comments
 (0)