mirror of
https://github.com/openharmony/third_party_rust_rustix.git
synced 2026-07-19 23:03:36 -04:00
Fix dir iterator in case of an error.
Do not resize internal buffer on error, otherwise iterator gets stuck in infinite loop with zeroed `dirent`s after the first error. Correct behavior is to return error indefinitely if it persists. Error can be ENOENT if the directory is unlinked while iterating, for example. Signed-off-by: Aleksandr Trukhin <alxtry@gmail.com>
This commit is contained in:
committed by
Dan Gohman
parent
b72d4291d2
commit
36d79738cc
@@ -136,15 +136,19 @@ impl Dir {
|
||||
}
|
||||
|
||||
fn read_more(&mut self) -> Option<io::Result<()>> {
|
||||
let og_len = self.buf.len();
|
||||
// Capacity increment currently chosen by wild guess.
|
||||
self.buf
|
||||
.resize(self.buf.capacity() + 32 * size_of::<linux_dirent64>(), 0);
|
||||
self.pos = 0;
|
||||
let nread = match crate::backend::fs::syscalls::getdents(self.fd.as_fd(), &mut self.buf) {
|
||||
Ok(nread) => nread,
|
||||
Err(err) => return Some(Err(err)),
|
||||
Err(err) => {
|
||||
self.buf.resize(og_len, 0);
|
||||
return Some(Err(err));
|
||||
}
|
||||
};
|
||||
self.buf.resize(nread, 0);
|
||||
self.pos = 0;
|
||||
if nread == 0 {
|
||||
None
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user