File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed
Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -987,8 +987,6 @@ impl Options {
987987 let not_implemented_opts = vec ! [
988988 #[ cfg( not( any( windows, unix) ) ) ]
989989 options:: ONE_FILE_SYSTEM ,
990- #[ cfg( windows) ]
991- options:: FORCE ,
992990 ] ;
993991
994992 for not_implemented_opt in not_implemented_opts {
@@ -1991,6 +1989,16 @@ fn delete_dest_if_needed_and_allowed(
19911989}
19921990
19931991fn delete_path ( path : & Path , options : & Options ) -> CopyResult < ( ) > {
1992+ // Windows requires clearing readonly attribute before deletion when using --force
1993+ #[ cfg( windows) ]
1994+ if options. force ( ) {
1995+ if let Ok ( mut perms) = fs:: metadata ( path) . map ( |m| m. permissions ( ) ) {
1996+ #[ allow( clippy:: permissions_set_readonly_false) ]
1997+ perms. set_readonly ( false ) ;
1998+ let _ = fs:: set_permissions ( path, perms) ;
1999+ }
2000+ }
2001+
19942002 match fs:: remove_file ( path) {
19952003 Ok ( ( ) ) => {
19962004 if options. verbose {
Original file line number Diff line number Diff line change @@ -11,7 +11,6 @@ use uucore::selinux::get_getfattr_output;
1111use uutests:: util:: TestScenario ;
1212use uutests:: { at_and_ucmd, new_ucmd, path_concat, util_name} ;
1313
14- #[ cfg( not( windows) ) ]
1514use std:: fs:: set_permissions;
1615
1716use std:: io:: Write ;
@@ -972,7 +971,6 @@ fn test_cp_arg_no_clobber_twice() {
972971}
973972
974973#[ test]
975- #[ cfg( not( windows) ) ]
976974fn test_cp_arg_force ( ) {
977975 let ( at, mut ucmd) = at_and_ucmd ! ( ) ;
978976
You can’t perform that action at this time.
0 commit comments