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

Function _getdiskusage

crates/vm/src/stdlib/nt.rs:1745–1774  ·  view source on GitHub ↗
(path: OsPath, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1743
1744 #[pyfunction]
1745 fn _getdiskusage(path: OsPath, vm: &VirtualMachine) -> PyResult<(u64, u64)> {
1746 use FileSystem::GetDiskFreeSpaceExW;
1747
1748 let wpath = path.to_wide_cstring(vm)?;
1749 let mut _free_to_me: u64 = 0;
1750 let mut total: u64 = 0;
1751 let mut free: u64 = 0;
1752 let ret =
1753 unsafe { GetDiskFreeSpaceExW(wpath.as_ptr(), &mut _free_to_me, &mut total, &mut free) };
1754 if ret != 0 {
1755 return Ok((total, free));
1756 }
1757 let err = io::Error::last_os_error();
1758 if err.raw_os_error() == Some(Foundation::ERROR_DIRECTORY as i32)
1759 && let Some(parent) = path.as_ref().parent()
1760 {
1761 let parent = widestring::WideCString::from_os_str(parent).unwrap();
1762
1763 let ret = unsafe {
1764 GetDiskFreeSpaceExW(parent.as_ptr(), &mut _free_to_me, &mut total, &mut free)
1765 };
1766
1767 return if ret == 0 {
1768 Err(err.to_pyexception(vm))
1769 } else {
1770 Ok((total, free))
1771 };
1772 }
1773 Err(err.to_pyexception(vm))
1774 }
1775
1776 #[pyfunction]
1777 fn get_handle_inheritable(handle: intptr_t, vm: &VirtualMachine) -> PyResult<bool> {

Callers

nothing calls this directly

Calls 8

SomeClass · 0.50
ErrClass · 0.50
to_wide_cstringMethod · 0.45
as_ptrMethod · 0.45
parentMethod · 0.45
as_refMethod · 0.45
unwrapMethod · 0.45
to_pyexceptionMethod · 0.45

Tested by

no test coverage detected