Skip to content

Commit 23d1b05

Browse files
authored
Rollup merge of #103005 - solid-rs:patch/kmc-solid/readdir-terminator, r=m-ou-se
kmc-solid: Handle errors returned by `SOLID_FS_ReadDir` Fixes the issue where the `std::fs::ReadDir` implementaton of the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets silently suppressed errors returned by the underlying `SOLID_FS_ReadDir` system function. The new implementation correctly handles all cases: - `SOLID_ERR_NOTFOUND` indicates the end of directory stream. - `SOLID_ERR_OK` + non-empty `d_name` indicates success. - Some old filesystem drivers may return `SOLID_ERR_OK` + empty `d_name` to indicate the end of directory stream. - Any other negative values (per ITRON convention) represent an error.
2 parents 214fa9f + 76bec17 commit 23d1b05

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)