@@ -18,7 +18,7 @@ use std::os::unix::fs::MetadataExt;
18
18
use std:: os:: unix:: prelude:: OsStrExt ;
19
19
use std:: path:: { Path , PathBuf , MAIN_SEPARATOR } ;
20
20
use std:: process;
21
- use std:: { fs , io } ;
21
+ use std:: fs ;
22
22
use uucore:: backup_control:: { self , BackupMode } ;
23
23
use uucore:: display:: Quotable ;
24
24
use uucore:: entries:: { grp2gid, usr2uid} ;
@@ -736,18 +736,6 @@ fn perform_backup(to: &Path, b: &Behavior) -> UResult<Option<PathBuf>> {
736
736
}
737
737
}
738
738
739
- fn copy_file_source_not_dev_null ( from : & Path , to : & Path ) -> io:: Result < ( ) > {
740
- let dest_meta_res = fs:: symlink_metadata ( to) ;
741
- if let Ok ( dest_meta) = dest_meta_res {
742
- if dest_meta. is_symlink ( ) {
743
- // fs::copy fails if destination is a invalid symlink
744
- // so lets just remove all symlinks at destination before copy
745
- fs:: remove_file ( to) ?;
746
- }
747
- }
748
- fs:: copy ( from, to) . map ( |_| ( ) )
749
- }
750
-
751
739
/// Copy a file from one path to another.
752
740
///
753
741
/// # Parameters
@@ -760,6 +748,15 @@ fn copy_file_source_not_dev_null(from: &Path, to: &Path) -> io::Result<()> {
760
748
/// Returns an empty Result or an error in case of failure.
761
749
///
762
750
fn copy_file ( from : & Path , to : & Path ) -> UResult < ( ) > {
751
+ let dest_meta_res = fs:: symlink_metadata ( to) ;
752
+ if let Ok ( dest_meta) = dest_meta_res {
753
+ if dest_meta. is_symlink ( ) {
754
+ // fs::copy fails if destination is a invalid symlink
755
+ // so lets just remove all symlinks at destination before copy
756
+ fs:: remove_file ( to) ?;
757
+ }
758
+ }
759
+
763
760
if from. as_os_str ( ) == "/dev/null" {
764
761
/* workaround a limitation of fs::copy
765
762
* https://github.com/rust-lang/rust/issues/79390
@@ -769,13 +766,8 @@ fn copy_file(from: &Path, to: &Path) -> UResult<()> {
769
766
InstallError :: InstallFailed ( from. to_path_buf ( ) , to. to_path_buf ( ) , err) . into ( ) ,
770
767
) ;
771
768
}
772
- } else {
773
- let result = copy_file_source_not_dev_null ( from, to) ;
774
- if let Err ( err) = result {
775
- return Err (
776
- InstallError :: InstallFailed ( from. to_path_buf ( ) , to. to_path_buf ( ) , err) . into ( ) ,
777
- ) ;
778
- }
769
+ } else if let Err ( err) = fs:: copy ( from, to) {
770
+ return Err ( InstallError :: InstallFailed ( from. to_path_buf ( ) , to. to_path_buf ( ) , err) . into ( ) ) ;
779
771
}
780
772
Ok ( ( ) )
781
773
}
0 commit comments