@@ -3365,6 +3365,29 @@ fn test_copy_dir_preserve_permissions() {
3365
3365
assert_metadata_eq ! ( metadata1, metadata2) ;
3366
3366
}
3367
3367
3368
+ /// cp should preserve attributes of subdirectories when copying recursively.
3369
+ #[ cfg( all( not( windows) , not( target_os = "freebsd" ) , not( target_os = "openbsd" ) ) ) ]
3370
+ #[ test]
3371
+ fn test_copy_dir_preserve_subdir_permissions ( ) {
3372
+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
3373
+ at. mkdir ( "a1" ) ;
3374
+ at. mkdir ( "a1/a2" ) ;
3375
+ // Use different permissions for a better test
3376
+ at. set_mode ( "a1/a2" , 0o0555 ) ;
3377
+ at. set_mode ( "a1" , 0o0777 ) ;
3378
+
3379
+ ucmd. args ( & [ "-p" , "-r" , "a1" , "b1" ] )
3380
+ . succeeds ( )
3381
+ . no_stderr ( )
3382
+ . no_stdout ( ) ;
3383
+
3384
+ // Make sure everything is preserved
3385
+ assert ! ( at. dir_exists( "b1" ) ) ;
3386
+ assert ! ( at. dir_exists( "b1/a2" ) ) ;
3387
+ assert_metadata_eq ! ( at. metadata( "a1" ) , at. metadata( "b1" ) ) ;
3388
+ assert_metadata_eq ! ( at. metadata( "a1/a2" ) , at. metadata( "b1/a2" ) ) ;
3389
+ }
3390
+
3368
3391
/// Test for preserving permissions when copying a directory, even in
3369
3392
/// the face of an inaccessible file in that directory.
3370
3393
#[ cfg( all( not( windows) , not( target_os = "freebsd" ) , not( target_os = "openbsd" ) ) ) ]
@@ -5616,7 +5639,7 @@ mod link_deref {
5616
5639
// which could be problematic if we aim to preserve ownership or mode. For example, when
5617
5640
// copying a directory, the destination directory could temporarily be setgid on some filesystems.
5618
5641
// This temporary setgid status could grant access to other users who share the same group
5619
- // ownership as the newly created directory.To mitigate this issue, when creating a directory we
5642
+ // ownership as the newly created directory. To mitigate this issue, when creating a directory we
5620
5643
// disable these excessive permissions.
5621
5644
#[ test]
5622
5645
#[ cfg( unix) ]
0 commit comments