MCPcopy Index your code
hub / github.com/RustPython/RustPython / _test_file_exists

Function _test_file_exists

crates/vm/src/stdlib/nt.rs:776–796  ·  view source on GitHub ↗

_testFileExists wrapper - handles both fd and path

(path_or_fd: &OsPathOrFd<'_>, follow_links: bool)

Source from the content-addressed store, hash-verified

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)

Callers 2

_path_existsFunction · 0.85
_path_lexistsFunction · 0.85

Calls 5

as_handleFunction · 0.85
GetFileTypeFunction · 0.85
GetLastErrorFunction · 0.70
as_refMethod · 0.45

Tested by

no test coverage detected