_testFileExists wrapper - handles both fd and path
(path_or_fd: &OsPathOrFd<'_>, follow_links: bool)
| 774 | |
| 775 | /// _testFileExists wrapper - handles both fd and path |
| 776 | fn _test_file_exists(path_or_fd: &OsPathOrFd<'_>, follow_links: bool) -> bool { |
| 777 | use windows_sys::Win32::Storage::FileSystem::{FILE_TYPE_UNKNOWN, GetFileType}; |
| 778 | |
| 779 | match path_or_fd { |
| 780 | OsPathOrFd::Fd(fd) => { |
| 781 | if let Ok(handle) = crate::common::crt_fd::as_handle(*fd) { |
| 782 | use std::os::windows::io::AsRawHandle; |
| 783 | let file_type = unsafe { GetFileType(handle.as_raw_handle() as _) }; |
| 784 | // GetFileType(hfile) != FILE_TYPE_UNKNOWN || !GetLastError() |
| 785 | if file_type != FILE_TYPE_UNKNOWN { |
| 786 | return true; |
| 787 | } |
| 788 | // Check if GetLastError is 0 (no error means valid handle) |
| 789 | unsafe { windows_sys::Win32::Foundation::GetLastError() == 0 } |
| 790 | } else { |
| 791 | false |
| 792 | } |
| 793 | } |
| 794 | OsPathOrFd::Path(path) => _test_file_exists_by_name(path.as_ref(), follow_links), |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | /// Check if a path is a directory. |
| 799 | /// return _testFileType(path, PY_IFDIR) |
no test coverage detected