@@ -259,9 +259,10 @@ impl Drop for UmaskGuard {
259259
260260/// Create a directory with the exact mode specified, bypassing umask.
261261///
262- /// GNU mkdir temporarily sets umask to shaped mask before calling mkdir(2), ensuring the
263- /// directory is created atomically with the correct permissions. This avoids a
264- /// race condition where the directory briefly exists with umask-based permissions.
262+ /// GNU mkdir temporarily sets umask to a shaped umask before calling mkdir(2),
263+ /// ensuring the directory is created atomically with the correct permissions.
264+ /// This avoids a race condition where the directory briefly exists with
265+ /// umask-based permissions.
265266#[ cfg( unix) ]
266267fn create_dir_with_mode (
267268 path : & Path ,
@@ -282,30 +283,24 @@ fn create_dir_with_mode(path: &Path, _mode: u32, _shaped_umask: u32) -> std::io:
282283
283284// Helper function to create a single directory with appropriate permissions
284285// `is_parent` argument is not used on windows
285- #[ allow( unused_variables) ]
286+ #[ cfg_attr ( not ( unix ) , allow( unused_variables) ) ]
286287fn create_single_dir ( path : & Path , is_parent : bool , config : & Config ) -> UResult < ( ) > {
287288 #[ cfg( unix) ]
288289 let ( mkdir_mode, shaped_umask) = {
289- let umask = mode :: get_umask ( ) ;
290- let umask_bits = rustix :: fs :: Mode :: from_bits_truncate ( umask as rustix :: fs :: RawMode ) ;
290+ let mode_bits = | x : u32 | rustix :: fs :: Mode :: from_bits_truncate ( x as rustix :: fs :: RawMode ) ;
291+ let umask_bits = mode_bits ( mode :: get_umask ( ) ) ;
291292 if is_parent {
292293 // Parent directories are never affected by -m (matches GNU behavior).
293294 // We pass 0o777 as the mode and shape the umask so it cannot block
294295 // owner write or execute (u+wx), ensuring the owner can traverse and
295296 // write into the parent to create children. All other umask bits are
296297 // preserved so the kernel applies them — and any default ACL on the
297298 // grandparent — through the normal mkdir(2) path.
298- (
299- DEFAULT_PERM ,
300- umask_bits & !rustix:: fs:: Mode :: from_bits_truncate ( 0o300 as rustix:: fs:: RawMode ) ,
301- )
299+ ( DEFAULT_PERM , umask_bits & !mode_bits ( 0o300 ) )
302300 } else {
303301 match config. mode {
304302 // Explicit -m: shape umask so it cannot block explicitly requested bits.
305- Some ( m) => (
306- m,
307- umask_bits & !rustix:: fs:: Mode :: from_bits_truncate ( m as rustix:: fs:: RawMode ) ,
308- ) ,
303+ Some ( m) => ( m, umask_bits & !mode_bits ( m) ) ,
309304 // No -m: leave umask fully intact; kernel applies umask + ACL naturally.
310305 None => ( DEFAULT_PERM , umask_bits) ,
311306 }
0 commit comments