Skip to content

Commit 39fa9de

Browse files
committed
mkdir: use uucore::mode::UmaskGuard instead of local implementation
1 parent 90f7756 commit 39fa9de

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

src/uu/mkdir/src/mkdir.rs

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// For the full copyright and license information, please view the LICENSE
44
// file that was distributed with this source code.
55

6-
// spell-checker:ignore (ToDO) ugoa cmode RAII
6+
// spell-checker:ignore (ToDO) ugoa cmode
77

88
use clap::builder::ValueParser;
99
use clap::parser::ValuesRef;
@@ -245,28 +245,6 @@ fn create_dir(path: &Path, is_parent: bool, config: &Config) -> UResult<()> {
245245
create_single_dir(path, is_parent, config)
246246
}
247247

248-
/// RAII guard to restore umask on drop, ensuring cleanup even on panic.
249-
#[cfg(unix)]
250-
struct UmaskGuard(uucore::libc::mode_t);
251-
252-
#[cfg(unix)]
253-
impl UmaskGuard {
254-
/// Set umask to the given value and return a guard that restores the original on drop.
255-
fn set(new_mask: uucore::libc::mode_t) -> Self {
256-
let old_mask = unsafe { uucore::libc::umask(new_mask) };
257-
Self(old_mask)
258-
}
259-
}
260-
261-
#[cfg(unix)]
262-
impl Drop for UmaskGuard {
263-
fn drop(&mut self) {
264-
unsafe {
265-
uucore::libc::umask(self.0);
266-
}
267-
}
268-
}
269-
270248
/// Create a directory with the exact mode specified, bypassing umask.
271249
///
272250
/// GNU mkdir temporarily sets umask to 0 before calling mkdir(2), ensuring the
@@ -278,7 +256,7 @@ fn create_dir_with_mode(path: &Path, mode: u32) -> std::io::Result<()> {
278256

279257
// Temporarily set umask to 0 so the directory is created with the exact mode.
280258
// The guard restores the original umask on drop, even if we panic.
281-
let _guard = UmaskGuard::set(0);
259+
let _guard = mode::UmaskGuard::set(0);
282260

283261
std::fs::DirBuilder::new().mode(mode).create(path)
284262
}

0 commit comments

Comments
 (0)