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

Function rmdir

crates/vm/src/stdlib/os.rs:377–396  ·  view source on GitHub ↗
(
        path: OsPath,
        dir_fd: DirFd<'_, { RMDIR_DIR_FD as usize }>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

375 #[cfg(not(windows))]
376 #[pyfunction]
377 fn rmdir(
378 path: OsPath,
379 dir_fd: DirFd<'_, { RMDIR_DIR_FD as usize }>,
380 vm: &VirtualMachine,
381 ) -> PyResult<()> {
382 #[cfg(not(target_os = "redox"))]
383 if let Some(fd) = dir_fd.raw_opt() {
384 let c_path = path.clone().into_cstring(vm)?;
385 let res = unsafe { libc::unlinkat(fd, c_path.as_ptr(), libc::AT_REMOVEDIR) };
386 return if res < 0 {
387 let err = crate::common::os::errno_io_error();
388 Err(OSErrorBuilder::with_filename(&err, path, vm))
389 } else {
390 Ok(())
391 };
392 }
393 #[cfg(target_os = "redox")]
394 let [] = dir_fd.0;
395 fs::remove_dir(&path).map_err(|err| OSErrorBuilder::with_filename(&err, path, vm))
396 }
397
398 #[cfg(windows)]
399 #[pyfunction]

Callers

nothing calls this directly

Calls 6

errno_io_errorFunction · 0.85
raw_optMethod · 0.80
into_cstringMethod · 0.80
ErrClass · 0.50
cloneMethod · 0.45
as_ptrMethod · 0.45

Tested by

no test coverage detected