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
88use clap:: builder:: ValueParser ;
99use 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