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

Function listvolumes

crates/vm/src/stdlib/nt.rs:1850–1881  ·  view source on GitHub ↗
(vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1848
1849 #[pyfunction]
1850 fn listvolumes(vm: &VirtualMachine) -> PyResult<PyListRef> {
1851 use windows_sys::Win32::Foundation::ERROR_NO_MORE_FILES;
1852
1853 let mut result = Vec::new();
1854 let mut buffer = [0u16; Foundation::MAX_PATH as usize + 1];
1855
1856 let find = unsafe { FileSystem::FindFirstVolumeW(buffer.as_mut_ptr(), buffer.len() as _) };
1857 if find == INVALID_HANDLE_VALUE {
1858 return Err(vm.new_last_os_error());
1859 }
1860
1861 loop {
1862 // Find the null terminator
1863 let len = buffer.iter().position(|&c| c == 0).unwrap_or(buffer.len());
1864 let volume = String::from_utf16_lossy(&buffer[..len]);
1865 result.push(vm.new_pyobj(volume));
1866
1867 let ret = unsafe {
1868 FileSystem::FindNextVolumeW(find, buffer.as_mut_ptr(), buffer.len() as _)
1869 };
1870 if ret == 0 {
1871 let err = io::Error::last_os_error();
1872 unsafe { FileSystem::FindVolumeClose(find) };
1873 if err.raw_os_error() == Some(ERROR_NO_MORE_FILES as i32) {
1874 break;
1875 }
1876 return Err(err.to_pyexception(vm));
1877 }
1878 }
1879
1880 Ok(vm.ctx.new_list(result))
1881 }
1882
1883 #[pyfunction]
1884 fn listmounts(volume: OsPath, vm: &VirtualMachine) -> PyResult<PyListRef> {

Callers

nothing calls this directly

Calls 12

newFunction · 0.85
as_mut_ptrMethod · 0.80
new_last_os_errorMethod · 0.80
new_pyobjMethod · 0.80
new_listMethod · 0.80
ErrClass · 0.50
SomeClass · 0.50
lenMethod · 0.45
positionMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
to_pyexceptionMethod · 0.45

Tested by

no test coverage detected