@@ -698,8 +698,8 @@ fn rename_with_fallback(
698
698
// 1. Files are on different devices (EXDEV error)
699
699
// 2. On Windows, if the target file exists and source file is opened by another process
700
700
// (MoveFileExW fails with "Access Denied" even if the source file has FILE_SHARE_DELETE permission)
701
- let should_fallback = matches ! ( err . raw_os_error ( ) , Some ( EXDEV ) )
702
- || ( from. is_file ( ) && can_delete_file ( from) . unwrap_or ( false ) ) ;
701
+ let should_fallback =
702
+ matches ! ( err . raw_os_error ( ) , Some ( EXDEV ) ) || ( from. is_file ( ) && can_delete_file ( from) ) ;
703
703
if !should_fallback {
704
704
return Err ( err) ;
705
705
}
@@ -864,7 +864,7 @@ fn is_empty_dir(path: &Path) -> bool {
864
864
865
865
/// Checks if a file can be deleted by attempting to open it with delete permissions.
866
866
#[ cfg( windows) ]
867
- fn can_delete_file ( path : & Path ) -> Result < bool , io :: Error > {
867
+ fn can_delete_file ( path : & Path ) -> bool {
868
868
use std:: {
869
869
os:: windows:: ffi:: OsStrExt as _,
870
870
ptr:: { null, null_mut} ,
@@ -897,19 +897,19 @@ fn can_delete_file(path: &Path) -> Result<bool, io::Error> {
897
897
} ;
898
898
899
899
if handle == INVALID_HANDLE_VALUE {
900
- return Err ( io :: Error :: last_os_error ( ) ) ;
900
+ return false ;
901
901
}
902
902
903
903
unsafe { CloseHandle ( handle) } ;
904
904
905
- Ok ( true )
905
+ true
906
906
}
907
907
908
908
#[ cfg( not( windows) ) ]
909
- fn can_delete_file ( _: & Path ) -> Result < bool , io :: Error > {
909
+ fn can_delete_file ( _: & Path ) -> bool {
910
910
// On non-Windows platforms, always return false to indicate that we don't need
911
911
// to try the copy+delete fallback. This is because on Unix-like systems,
912
912
// rename() failing with errors other than EXDEV means the operation cannot
913
913
// succeed even with a copy+delete approach (e.g. permission errors).
914
- Ok ( false )
914
+ false
915
915
}
0 commit comments