@@ -1646,12 +1646,25 @@ impl Build {
16461646 paths
16471647 }
16481648
1649+
1650+ /// Copies a file from `src` to `dst`
1651+ // TODO: Rename to cp_r or something like that after #122590 has been merged.
1652+ pub fn copy_but_like_really_copy ( & self , src : & Path , dst : & Path ) {
1653+ self . copy_internal ( src, dst, false , false ) ;
1654+ }
1655+
16491656 /// Copies a file from `src` to `dst`
16501657 pub fn copy ( & self , src : & Path , dst : & Path ) {
1651- self . copy_internal ( src, dst, false ) ;
1658+ self . copy_internal ( src, dst, false , true ) ;
16521659 }
16531660
1654- fn copy_internal ( & self , src : & Path , dst : & Path , dereference_symlinks : bool ) {
1661+ fn copy_internal (
1662+ & self ,
1663+ src : & Path ,
1664+ dst : & Path ,
1665+ dereference_symlinks : bool ,
1666+ link_if_possible : bool ,
1667+ ) {
16551668 if self . config . dry_run ( ) {
16561669 return ;
16571670 }
@@ -1671,7 +1684,7 @@ impl Build {
16711684 return ;
16721685 }
16731686 }
1674- if let Ok ( ( ) ) = fs:: hard_link ( & src, dst) {
1687+ if link_if_possible && fs:: hard_link ( & src, dst) . is_ok ( ) {
16751688 // Attempt to "easy copy" by creating a hard link
16761689 // (symlinks don't work on windows), but if that fails
16771690 // just fall back to a slow `copy` operation.
@@ -1706,6 +1719,25 @@ impl Build {
17061719 }
17071720 }
17081721
1722+ // TODO: Rename to cp_r or something like that after #122590 has been merged.
1723+ pub fn cp_r_but_like_really_copy ( & self , src : & Path , dst : & Path ) {
1724+ if self . config . dry_run ( ) {
1725+ return ;
1726+ }
1727+ for f in self . read_dir ( src) {
1728+ let path = f. path ( ) ;
1729+ let name = path. file_name ( ) . unwrap ( ) ;
1730+ let dst = dst. join ( name) ;
1731+ if t ! ( f. file_type( ) ) . is_dir ( ) {
1732+ t ! ( fs:: create_dir_all( & dst) ) ;
1733+ self . cp_r_but_like_really_copy ( & path, & dst) ;
1734+ } else {
1735+ let _ = fs:: remove_file ( & dst) ;
1736+ self . copy_but_like_really_copy ( & path, & dst) ;
1737+ }
1738+ }
1739+ }
1740+
17091741 /// Copies the `src` directory recursively to `dst`. Both are assumed to exist
17101742 /// when this function is called. Unwanted files or directories can be skipped
17111743 /// by returning `false` from the filter function.
@@ -1751,7 +1783,7 @@ impl Build {
17511783 if !src. exists ( ) {
17521784 panic ! ( "ERROR: File \" {}\" not found!" , src. display( ) ) ;
17531785 }
1754- self . copy_internal ( src, & dst, true ) ;
1786+ self . copy_internal ( src, & dst, true , true ) ;
17551787 chmod ( & dst, perms) ;
17561788 }
17571789
0 commit comments