@@ -968,42 +968,20 @@ fn rename_fifo_fallback(_from: &Path, _to: &Path) -> io::Result<()> {
968968/// symlinks return an error.
969969#[ cfg( unix) ]
970970fn rename_symlink_fallback ( from : & Path , to : & Path ) -> io:: Result < ( ) > {
971- let from_meta = from. symlink_metadata ( ) ?;
972- let path_symlink_points_to = fs:: read_link ( from) ?;
973- unix:: fs:: symlink ( path_symlink_points_to, to) ?;
974- #[ cfg( not( any( target_os = "macos" , target_os = "redox" ) ) ) ]
975- {
976- let _ = copy_xattrs_if_supported ( from, to) ;
977- }
978- try_preserve_ownership ( & from_meta, to, false ) ;
971+ copy_symlink ( from, to) ?;
979972 fs:: remove_file ( from)
980973}
981974
982975#[ cfg( windows) ]
983976fn rename_symlink_fallback ( from : & Path , to : & Path ) -> io:: Result < ( ) > {
984- let path_symlink_points_to = fs:: read_link ( from) ?;
985- if path_symlink_points_to. exists ( ) {
986- if path_symlink_points_to. is_dir ( ) {
987- windows:: fs:: symlink_dir ( & path_symlink_points_to, to) ?;
988- } else {
989- windows:: fs:: symlink_file ( & path_symlink_points_to, to) ?;
990- }
991- fs:: remove_file ( from)
992- } else {
993- Err ( io:: Error :: new (
994- io:: ErrorKind :: NotFound ,
995- translate ! ( "mv-error-dangling-symlink" ) ,
996- ) )
997- }
977+ copy_symlink ( from, to) ?;
978+ fs:: remove_file ( from)
998979}
999980
1000981#[ cfg( not( any( windows, unix) ) ) ]
1001982fn rename_symlink_fallback ( from : & Path , to : & Path ) -> io:: Result < ( ) > {
1002- let path_symlink_points_to = fs:: read_link ( from) ?;
1003- Err ( io:: Error :: new (
1004- io:: ErrorKind :: Other ,
1005- translate ! ( "mv-error-no-symlink-support" ) ,
1006- ) )
983+ copy_symlink ( from, to) ?;
984+ fs:: remove_file ( from)
1007985}
1008986
1009987/// Copy the given symlink to the given destination without dereferencing.
@@ -1012,9 +990,13 @@ fn rename_symlink_fallback(from: &Path, to: &Path) -> io::Result<()> {
1012990fn copy_symlink ( from : & Path , to : & Path ) -> io:: Result < ( ) > {
1013991 let from_meta = from. symlink_metadata ( ) ?;
1014992 let path_symlink_points_to = fs:: read_link ( from) ?;
1015- unix:: fs:: symlink ( path_symlink_points_to, to) . map ( |_| {
1016- try_preserve_ownership ( & from_meta, to, false ) ;
1017- } )
993+ unix:: fs:: symlink ( path_symlink_points_to, to) ?;
994+ #[ cfg( not( any( target_os = "macos" , target_os = "redox" ) ) ) ]
995+ {
996+ let _ = copy_xattrs_if_supported ( from, to) ;
997+ }
998+ try_preserve_ownership ( & from_meta, to, false ) ;
999+ Ok ( ( ) )
10181000}
10191001
10201002#[ cfg( windows) ]
@@ -1231,7 +1213,7 @@ fn copy_dir_contents_recursive(
12311213 {
12321214 if from_path. is_symlink ( ) {
12331215 // Copy a symlink file (no-follow).
1234- rename_symlink_fallback ( & from_path, & to_path) ?;
1216+ copy_symlink ( & from_path, & to_path) ?;
12351217 } else {
12361218 // Copy a regular file.
12371219 fs:: copy ( & from_path, & to_path) ?;
@@ -1282,7 +1264,7 @@ fn copy_file_with_hardlinks_helper(
12821264
12831265 if from_meta. file_type ( ) . is_symlink ( ) {
12841266 // Copy a symlink file (no-follow).
1285- rename_symlink_fallback ( from, to) ?;
1267+ copy_symlink ( from, to) ?;
12861268 } else {
12871269 // Copy a regular file.
12881270 fs:: copy ( from, to) ?;
0 commit comments