(path: OsPath, vm: &VirtualMachine)
| 1289 | |
| 1290 | #[pyfunction] |
| 1291 | fn _getfinalpathname(path: OsPath, vm: &VirtualMachine) -> PyResult { |
| 1292 | use windows_sys::Win32::Storage::FileSystem::{ |
| 1293 | CreateFileW, FILE_FLAG_BACKUP_SEMANTICS, GetFinalPathNameByHandleW, OPEN_EXISTING, |
| 1294 | VOLUME_NAME_DOS, |
| 1295 | }; |
| 1296 | |
| 1297 | let wide = path.to_wide_cstring(vm)?; |
| 1298 | let handle = unsafe { |
| 1299 | CreateFileW( |
| 1300 | wide.as_ptr(), |
| 1301 | 0, |
| 1302 | 0, |
| 1303 | core::ptr::null(), |
| 1304 | OPEN_EXISTING, |
| 1305 | FILE_FLAG_BACKUP_SEMANTICS, |
| 1306 | core::ptr::null_mut(), |
| 1307 | ) |
| 1308 | }; |
| 1309 | if handle == INVALID_HANDLE_VALUE { |
| 1310 | let err = io::Error::last_os_error(); |
| 1311 | return Err(OSErrorBuilder::with_filename(&err, path, vm)); |
| 1312 | } |
| 1313 | |
| 1314 | let mut buffer: Vec<u16> = vec![0; Foundation::MAX_PATH as usize]; |
| 1315 | let result = loop { |
| 1316 | let ret = unsafe { |
| 1317 | GetFinalPathNameByHandleW( |
| 1318 | handle, |
| 1319 | buffer.as_mut_ptr(), |
| 1320 | buffer.len() as u32, |
| 1321 | VOLUME_NAME_DOS, |
| 1322 | ) |
| 1323 | }; |
| 1324 | if ret == 0 { |
| 1325 | let err = io::Error::last_os_error(); |
| 1326 | let _ = unsafe { Foundation::CloseHandle(handle) }; |
| 1327 | return Err(OSErrorBuilder::with_filename(&err, path, vm)); |
| 1328 | } |
| 1329 | if (ret as usize) < buffer.len() { |
| 1330 | let final_path = std::ffi::OsString::from_wide(&buffer[..ret as usize]); |
| 1331 | break Ok(path.mode().process_path(final_path, vm)); |
| 1332 | } |
| 1333 | buffer.resize(ret as usize, 0); |
| 1334 | }; |
| 1335 | |
| 1336 | unsafe { Foundation::CloseHandle(handle) }; |
| 1337 | result |
| 1338 | } |
| 1339 | |
| 1340 | #[pyfunction] |
| 1341 | fn _getfullpathname(path: OsPath, vm: &VirtualMachine) -> PyResult { |
no test coverage detected