Get file info using FindFirstFileW (fallback when CreateFileW fails) Ported from attributes_from_dir
(
path: &OsStr,
)
| 233 | /// Get file info using FindFirstFileW (fallback when CreateFileW fails) |
| 234 | /// Ported from attributes_from_dir |
| 235 | fn attributes_from_dir( |
| 236 | path: &OsStr, |
| 237 | ) -> std::io::Result<( |
| 238 | windows_sys::Win32::Storage::FileSystem::BY_HANDLE_FILE_INFORMATION, |
| 239 | u32, |
| 240 | )> { |
| 241 | use windows_sys::Win32::Storage::FileSystem::{ |
| 242 | BY_HANDLE_FILE_INFORMATION, FILE_ATTRIBUTE_REPARSE_POINT, FindClose, FindFirstFileW, |
| 243 | WIN32_FIND_DATAW, |
| 244 | }; |
| 245 | |
| 246 | let wide: Vec<u16> = path.to_wide_with_nul(); |
| 247 | let mut find_data: WIN32_FIND_DATAW = unsafe { core::mem::zeroed() }; |
| 248 | |
| 249 | let handle = unsafe { FindFirstFileW(wide.as_ptr(), &mut find_data) }; |
| 250 | if handle == INVALID_HANDLE_VALUE { |
| 251 | return Err(std::io::Error::last_os_error()); |
| 252 | } |
| 253 | unsafe { FindClose(handle) }; |
| 254 | |
| 255 | let mut info: BY_HANDLE_FILE_INFORMATION = unsafe { core::mem::zeroed() }; |
| 256 | info.dwFileAttributes = find_data.dwFileAttributes; |
| 257 | info.ftCreationTime = find_data.ftCreationTime; |
| 258 | info.ftLastAccessTime = find_data.ftLastAccessTime; |
| 259 | info.ftLastWriteTime = find_data.ftLastWriteTime; |
| 260 | info.nFileSizeHigh = find_data.nFileSizeHigh; |
| 261 | info.nFileSizeLow = find_data.nFileSizeLow; |
| 262 | |
| 263 | let reparse_tag = if find_data.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT != 0 { |
| 264 | find_data.dwReserved0 |
| 265 | } else { |
| 266 | 0 |
| 267 | }; |
| 268 | |
| 269 | Ok((info, reparse_tag)) |
| 270 | } |
| 271 | |
| 272 | /// Ported from win32_xstat_slow_impl |
| 273 | fn win32_xstat_slow_impl(path: &OsStr, traverse: bool) -> std::io::Result<StatStruct> { |
no test coverage detected