FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

host_env: rustix for unlinkat, fix clippy deny by joshuamegnauth54 · Pull Request #8591 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rs  (5) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 0 additions & 10 deletions crates/host_env/src/posix.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,6 @@ pub fn chroot(path: &Path) -> std::io::Result<()> {
nix::unistd::chroot(path).map_err(std::io::Error::from)
}

#[cfg(not(target_os = "redox"))]
pub fn unlinkat(dir_fd: i32, path: &CStr) -> std::io::Result<()> {
let ret = unsafe { libc::unlinkat(dir_fd, path.as_ptr(), 0) };
if ret < 0 {
Err(std::io::Error::last_os_error())
} else {
Ok(())
}
}

#[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "netbsd"))]
pub fn lchmod(path: &CStr, mode: libc::mode_t) -> std::io::Result<()> {
unsafe extern "C" {
Expand Down
5 changes: 5 additions & 0 deletions crates/host_env/src/posix_unix_like.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,8 @@ pub fn stat_path(
.map(Option::Some)
.map_err(Into::into)
}

pub fn unlinkat(dir_fd: Option<crt_fd::Borrowed<'_>>, path: impl AsRef<Path>) -> io::Result<()> {
let dir_fd = dir_fd.as_ref().map_or(fs::CWD, AsFd::as_fd);
fs::unlinkat(dir_fd, path.as_ref(), AtFlags::empty()).map_err(Into::into)
}
2 changes: 1 addition & 1 deletion crates/vm/src/stdlib/os.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ pub(super) mod _os {
const STAT_DIR_FD: bool = cfg!(not(any(windows, target_os = "redox")));
const UTIME_DIR_FD: bool = cfg!(not(any(windows, target_os = "redox")));
pub(crate) const SYMLINK_DIR_FD: bool = cfg!(not(any(windows, target_os = "redox")));
pub(crate) const UNLINK_DIR_FD: bool = cfg!(not(any(windows, target_os = "redox")));
pub(crate) const UNLINK_DIR_FD: bool = cfg!(not(windows));
const RENAME_DIR_FD: bool = cfg!(any(unix, target_os = "wasi"));
const RMDIR_DIR_FD: bool = cfg!(not(any(windows, target_os = "redox")));
const SCANDIR_FD: bool = cfg!(all(unix, not(target_os = "redox")));
Expand Down
10 changes: 1 addition & 9 deletions crates/vm/src/stdlib/posix.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -440,15 +440,7 @@ pub mod module {
dir_fd: DirFd<'_, { _os::UNLINK_DIR_FD as usize }>,
vm: &VirtualMachine,
) -> PyResult<()> {
#[cfg(not(target_os = "redox"))]
if let Some(fd) = dir_fd.raw_opt() {
let c_path = path.clone().into_cstring(vm)?;
return rustpython_host_env::posix::unlinkat(fd, &c_path)
.map_err(|err| OSErrorBuilder::with_filename(&err, path, vm));
}
#[cfg(target_os = "redox")]
let [] = dir_fd.0;
crate::host_env::fs::remove_file(&path)
rustpython_host_env::posix::unlinkat(dir_fd.get_opt(), &path)
.map_err(|err| OSErrorBuilder::with_filename(&err, path, vm))
}

Expand Down
21 changes: 19 additions & 2 deletions crates/vm/src/stdlib/posix_compat.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,34 @@ pub(crate) mod module {
use crate::{
Py, PyObjectRef, PyResult, VirtualMachine,
builtins::PyStrRef,
convert::IntoPyException,
ospath::OsPath,
stdlib::os::{_os, DirFd, SupportFunc, TargetIsDirectory},
};
use std::fs;

#[cfg(not(target_os = "wasi"))]
use {crate::convert::IntoPyException, std::fs};

#[cfg(target_os = "wasi")]
use crate::exceptions::OSErrorBuilder;

#[pyfunction]
pub(super) fn access(_path: PyStrRef, _mode: u8, vm: &VirtualMachine) -> PyResult<bool> {
os_unimpl("os.access", vm)
}

#[cfg(target_os = "wasi")]
#[pyfunction]
#[pyfunction(name = "unlink")]
fn remove(
path: OsPath,
dir_fd: DirFd<'_, { _os::UNLINK_DIR_FD as usize }>,
vm: &VirtualMachine,
) -> PyResult<()> {
rustpython_host_env::posix::unlinkat(dir_fd.get_opt(), &path)
.map_err(|err| OSErrorBuilder::with_filename(&err, path, vm))
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

#[cfg(not(target_os = "wasi"))]
Comment thread
coderabbitai[bot] marked this conversation as resolved.
#[pyfunction]
#[pyfunction(name = "unlink")]
fn remove(path: OsPath, dir_fd: DirFd<'_, 0>, vm: &VirtualMachine) -> PyResult<()> {
Expand Down
Loading

Back | FazBrowse Home | New Git URL