File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7444,3 +7444,28 @@ fn test_cp_archive_deref_flag_ordering() {
74447444 assert_eq ! ( at. is_symlink( & dest) , expect_symlink, "failed for {flags}" ) ;
74457445 }
74467446}
7447+
7448+ /// Test that copying to an existing file maintains its permissions, unix only because .mode() only
7449+ /// works on Unix
7450+ #[ test]
7451+ #[ cfg( unix) ]
7452+ fn test_cp_to_existing_file_permissions ( ) {
7453+ let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
7454+
7455+ at. touch ( "src" ) ;
7456+ at. touch ( "dst" ) ;
7457+
7458+ let src_path = at. plus ( "src" ) ;
7459+ let dst_path = at. plus ( "dst" ) ;
7460+
7461+ let mut src_permissions = std:: fs:: metadata ( & src_path) . unwrap ( ) . permissions ( ) ;
7462+ src_permissions. set_readonly ( true ) ;
7463+ std:: fs:: set_permissions ( & src_path, src_permissions) . unwrap ( ) ;
7464+
7465+ let dst_mode = std:: fs:: metadata ( & dst_path) . unwrap ( ) . permissions ( ) . mode ( ) ;
7466+
7467+ ucmd. args ( & [ "src" , "dst" ] ) . succeeds ( ) ;
7468+
7469+ let new_dst_mode = std:: fs:: metadata ( & dst_path) . unwrap ( ) . permissions ( ) . mode ( ) ;
7470+ assert_eq ! ( dst_mode, new_dst_mode) ;
7471+ }
You can’t perform that action at this time.
0 commit comments