Skip to content

Commit c2fc43c

Browse files
committed
std: sys: fs: uefi: Ignore "." and ".." when reading directory
At least in Unix, "." and ".." are not returned as a directory entry. So ignore these in UEFI as well. Signed-off-by: Ayush Singh <ayush@beagleboard.org>
1 parent 15f7c55 commit c2fc43c

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,15 @@ impl Iterator for ReadDir {
160160
fn next(&mut self) -> Option<io::Result<DirEntry>> {
161161
match self.0.read_dir_entry() {
162162
Ok(None) => None,
163-
Ok(Some(x)) => Some(Ok(DirEntry::from_uefi(x, self.0.path()))),
163+
Ok(Some(x)) => {
164+
let temp = DirEntry::from_uefi(x, self.0.path());
165+
// Ignore "." and "..". This is how ReadDir behaves in Unix.
166+
if temp.file_name == "." || temp.file_name == ".." {
167+
self.next()
168+
} else {
169+
Some(Ok(temp))
170+
}
171+
}
164172
Err(e) => Some(Err(e)),
165173
}
166174
}

0 commit comments

Comments
 (0)