@@ -1646,12 +1646,25 @@ impl Build {
1646
1646
paths
1647
1647
}
1648
1648
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
+
1649
1656
/// Copies a file from `src` to `dst`
1650
1657
pub fn copy ( & self , src : & Path , dst : & Path ) {
1651
- self . copy_internal ( src, dst, false ) ;
1658
+ self . copy_internal ( src, dst, false , true ) ;
1652
1659
}
1653
1660
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
+ ) {
1655
1668
if self . config . dry_run ( ) {
1656
1669
return ;
1657
1670
}
@@ -1671,7 +1684,7 @@ impl Build {
1671
1684
return ;
1672
1685
}
1673
1686
}
1674
- if let Ok ( ( ) ) = fs:: hard_link ( & src, dst) {
1687
+ if link_if_possible && fs:: hard_link ( & src, dst) . is_ok ( ) {
1675
1688
// Attempt to "easy copy" by creating a hard link
1676
1689
// (symlinks don't work on windows), but if that fails
1677
1690
// just fall back to a slow `copy` operation.
@@ -1706,6 +1719,25 @@ impl Build {
1706
1719
}
1707
1720
}
1708
1721
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
+
1709
1741
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
1710
1742
/// when this function is called. Unwanted files or directories can be skipped
1711
1743
/// by returning `false` from the filter function.
@@ -1751,7 +1783,7 @@ impl Build {
1751
1783
if !src. exists ( ) {
1752
1784
panic ! ( "ERROR: File \" {}\" not found!" , src. display( ) ) ;
1753
1785
}
1754
- self . copy_internal ( src, & dst, true ) ;
1786
+ self . copy_internal ( src, & dst, true , true ) ;
1755
1787
chmod ( & dst, perms) ;
1756
1788
}
1757
1789
0 commit comments