mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
fix: correct mkdirat implementation to use nix crate's mkdirat function (#11126)
The commit fixes an issue where the `mkdir_at` method was incorrectly using the raw libc `mkdirat` function instead of the nix crate's `mkdirat` function. This change ensures proper error handling and type safety by using the nix crate's wrapper, which provides better integration with Rust's type system and error handling patterns.
This commit is contained in:
@@ -24,7 +24,7 @@ use std::path::{Path, PathBuf};
|
||||
use nix::dir::Dir;
|
||||
use nix::fcntl::{OFlag, openat};
|
||||
use nix::libc;
|
||||
use nix::sys::stat::{FchmodatFlags, FileStat, Mode, fchmodat, fstatat};
|
||||
use nix::sys::stat::{FchmodatFlags, FileStat, Mode, fchmodat, fstatat, mkdirat};
|
||||
use nix::unistd::{Gid, Uid, UnlinkatFlags, fchown, fchownat, unlinkat};
|
||||
use os_display::Quotable;
|
||||
|
||||
@@ -323,12 +323,10 @@ impl DirFd {
|
||||
pub fn mkdir_at(&self, name: &OsStr, mode: u32) -> io::Result<()> {
|
||||
let name_cstr =
|
||||
CString::new(name.as_bytes()).map_err(|_| SafeTraversalError::PathContainsNull)?;
|
||||
let mode = mode as libc::mode_t;
|
||||
let fd = self.fd.as_raw_fd();
|
||||
let mode = Mode::from_bits_truncate(mode as libc::mode_t);
|
||||
|
||||
let result = unsafe { libc::mkdirat(fd, name_cstr.as_ptr(), mode) };
|
||||
if result == -1 {
|
||||
let err = io::Error::last_os_error();
|
||||
if let Err(e) = mkdirat(self.fd.as_fd(), name_cstr.as_c_str(), mode) {
|
||||
let err = io::Error::from_raw_os_error(e as i32);
|
||||
return Err(SafeTraversalError::OpenFailed {
|
||||
path: name.into(),
|
||||
source: err,
|
||||
|
||||
Reference in New Issue
Block a user