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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/uu/mkdir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ clap = { workspace = true }
uucore = { workspace = true, features = ["fs", "mode", "fsxattr"] }
fluent = { workspace = true }

[target.'cfg(unix)'.dependencies]
rustix = { workspace = true, features = ["process", "fs"] }

[features]
selinux = ["uucore/selinux"]
smack = ["uucore/smack"]
Expand Down
12 changes: 5 additions & 7 deletions src/uu/mkdir/src/mkdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,21 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {

/// RAII guard to restore umask on drop, ensuring cleanup even on panic.
#[cfg(unix)]
struct UmaskGuard(uucore::libc::mode_t);
struct UmaskGuard(rustix::fs::Mode);

#[cfg(unix)]
impl UmaskGuard {
/// Set umask to the given value and return a guard that restores the original on drop.
fn set(new_mask: uucore::libc::mode_t) -> Self {
let old_mask = unsafe { uucore::libc::umask(new_mask) };
fn set(new_mask: rustix::fs::Mode) -> Self {
let old_mask = rustix::process::umask(new_mask);
Self(old_mask)
}
}

#[cfg(unix)]
impl Drop for UmaskGuard {
fn drop(&mut self) {
unsafe {
uucore::libc::umask(self.0);
}
rustix::process::umask(self.0);
}
}

Expand All @@ -283,7 +281,7 @@ fn create_dir_with_mode(path: &Path, mode: u32) -> std::io::Result<()> {

// Temporarily set umask to 0 so the directory is created with the exact mode.
// The guard restores the original umask on drop, even if we panic.
let _guard = UmaskGuard::set(0);
let _guard = UmaskGuard::set(rustix::fs::Mode::empty());

std::fs::DirBuilder::new().mode(mode).create(path)
}
Expand Down
Loading