(zelf: &crate::Py<Self>, vm: &VirtualMachine)
| 958 | impl SelfIter for ScandirIterator {} |
| 959 | impl IterNext for ScandirIterator { |
| 960 | fn next(zelf: &crate::Py<Self>, vm: &VirtualMachine) -> PyResult<PyIterReturn> { |
| 961 | let entryref: &mut Option<fs::ReadDir> = &mut zelf.entries.write(); |
| 962 | |
| 963 | match entryref { |
| 964 | None => Ok(PyIterReturn::StopIteration(None)), |
| 965 | Some(inner) => match inner.next() { |
| 966 | Some(entry) => match entry { |
| 967 | Ok(entry) => { |
| 968 | #[cfg(unix)] |
| 969 | let ino = { |
| 970 | use std::os::unix::fs::DirEntryExt; |
| 971 | entry.ino() |
| 972 | }; |
| 973 | // TODO: wasi is nightly |
| 974 | // #[cfg(target_os = "wasi")] |
| 975 | // let ino = { |
| 976 | // use std::os::wasi::fs::DirEntryExt; |
| 977 | // entry.ino() |
| 978 | // }; |
| 979 | #[cfg(not(unix))] |
| 980 | let ino = None; |
| 981 | |
| 982 | let pathval = entry.path(); |
| 983 | |
| 984 | // On Windows, pre-cache lstat from directory entry metadata |
| 985 | // This allows stat() to return cached data even if file is removed |
| 986 | #[cfg(windows)] |
| 987 | let lstat = { |
| 988 | let cell = OnceCell::new(); |
| 989 | if let Ok(stat_struct) = |
| 990 | crate::windows::win32_xstat(pathval.as_os_str(), false) |
| 991 | { |
| 992 | let stat_obj = |
| 993 | StatResultData::from_stat(&stat_struct, vm).to_pyobject(vm); |
| 994 | let _ = cell.set(stat_obj); |
| 995 | } |
| 996 | cell |
| 997 | }; |
| 998 | #[cfg(not(windows))] |
| 999 | let lstat = OnceCell::new(); |
| 1000 | |
| 1001 | Ok(PyIterReturn::Return( |
| 1002 | DirEntry { |
| 1003 | file_name: entry.file_name(), |
| 1004 | pathval, |
| 1005 | file_type: entry.file_type(), |
| 1006 | #[cfg(unix)] |
| 1007 | d_type: None, |
| 1008 | #[cfg(not(any(windows, target_os = "redox")))] |
| 1009 | dir_fd: None, |
| 1010 | mode: zelf.mode, |
| 1011 | lstat, |
| 1012 | stat: OnceCell::new(), |
| 1013 | ino: AtomicCell::new(ino), |
| 1014 | } |
| 1015 | .into_ref(&vm.ctx) |
| 1016 | .into(), |
| 1017 | )) |
no test coverage detected