This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
library/std/src/sys/pal/windows Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,13 @@ impl fmt::Debug for ReadDir {
112112impl Iterator for ReadDir {
113113 type Item = io:: Result < DirEntry > ;
114114 fn next ( & mut self ) -> Option < io:: Result < DirEntry > > {
115+ if self . handle . 0 == c:: INVALID_HANDLE_VALUE {
116+ // This iterator was initialized with an `INVALID_HANDLE_VALUE` as its handle.
117+ // Simply return `None` because this is only the case when `FindFirstFileW` in
118+ // the construction of this iterator returns `ERROR_FILE_NOT_FOUND` which means
119+ // no matchhing files can be found.
120+ return None ;
121+ }
115122 if let Some ( first) = self . first . take ( ) {
116123 if let Some ( e) = DirEntry :: new ( & self . root , & first) {
117124 return Some ( Ok ( e) ) ;
@@ -1100,7 +1107,7 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
11001107 //
11011108 // Note: `ERROR_PATH_NOT_FOUND` would have been returned by the `FindFirstFileW` function
11021109 // when the path to search in does not exist in the first place.
1103- Err ( Error :: from_raw_os_error ( last_error. code as i32 ) ) ;
1110+ Err ( Error :: from_raw_os_error ( last_error. code as i32 ) )
11041111 }
11051112 }
11061113}
You can’t perform that action at this time.
0 commit comments