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

Function remove

crates/vm/src/stdlib/posix.rs:566–585  ·  view source on GitHub ↗
(
        path: OsPath,
        dir_fd: DirFd<'_, { _os::UNLINK_DIR_FD as usize }>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

564 #[pyfunction]
565 #[pyfunction(name = "unlink")]
566 fn remove(
567 path: OsPath,
568 dir_fd: DirFd<'_, { _os::UNLINK_DIR_FD as usize }>,
569 vm: &VirtualMachine,
570 ) -> PyResult<()> {
571 #[cfg(not(target_os = "redox"))]
572 if let Some(fd) = dir_fd.raw_opt() {
573 let c_path = path.clone().into_cstring(vm)?;
574 let res = unsafe { libc::unlinkat(fd, c_path.as_ptr(), 0) };
575 return if res < 0 {
576 let err = crate::common::os::errno_io_error();
577 Err(OSErrorBuilder::with_filename(&err, path, vm))
578 } else {
579 Ok(())
580 };
581 }
582 #[cfg(target_os = "redox")]
583 let [] = dir_fd.0;
584 fs::remove_file(&path).map_err(|err| OSErrorBuilder::with_filename(&err, path, vm))
585 }
586
587 #[cfg(not(target_os = "redox"))]
588 #[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