@@ -1646,12 +1646,24 @@ impl Build {
1646
1646
paths
1647
1647
}
1648
1648
1649
+ /// Copies a file from `src` to `dst`
1650
+ // TODO: Rename to cp_r or something like that after #122590 has been merged.
1651
+ pub fn copy_but_like_really_copy ( & self , src : & Path , dst : & Path ) {
1652
+ self . copy_internal ( src, dst, false , false ) ;
1653
+ }
1654
+
1649
1655
/// Copies a file from `src` to `dst`
1650
1656
pub fn copy ( & self , src : & Path , dst : & Path ) {
1651
- self . copy_internal ( src, dst, false ) ;
1657
+ self . copy_internal ( src, dst, false , true ) ;
1652
1658
}
1653
1659
1654
- fn copy_internal ( & self , src : & Path , dst : & Path , dereference_symlinks : bool ) {
1660
+ fn copy_internal (
1661
+ & self ,
1662
+ src : & Path ,
1663
+ dst : & Path ,
1664
+ dereference_symlinks : bool ,
1665
+ link_if_possible : bool ,
1666
+ ) {
1655
1667
if self . config . dry_run ( ) {
1656
1668
return ;
1657
1669
}
@@ -1671,7 +1683,7 @@ impl Build {
1671
1683
return ;
1672
1684
}
1673
1685
}
1674
- if let Ok ( ( ) ) = fs:: hard_link ( & src, dst) {
1686
+ if link_if_possible && fs:: hard_link ( & src, dst) . is_ok ( ) {
1675
1687
// Attempt to "easy copy" by creating a hard link
1676
1688
// (symlinks don't work on windows), but if that fails
1677
1689
// just fall back to a slow `copy` operation.
@@ -1706,6 +1718,25 @@ impl Build {
1706
1718
}
1707
1719
}
1708
1720
1721
+ // TODO: Rename to cp_r or something like that after #122590 has been merged.
1722
+ pub fn cp_r_but_like_really_copy ( & self , src : & Path , dst : & Path ) {
1723
+ if self . config . dry_run ( ) {
1724
+ return ;
1725
+ }
1726
+ for f in self . read_dir ( src) {
1727
+ let path = f. path ( ) ;
1728
+ let name = path. file_name ( ) . unwrap ( ) ;
1729
+ let dst = dst. join ( name) ;
1730
+ if t ! ( f. file_type( ) ) . is_dir ( ) {
1731
+ t ! ( fs:: create_dir_all( & dst) ) ;
1732
+ self . cp_r_but_like_really_copy ( & path, & dst) ;
1733
+ } else {
1734
+ let _ = fs:: remove_file ( & dst) ;
1735
+ self . copy_but_like_really_copy ( & path, & dst) ;
1736
+ }
1737
+ }
1738
+ }
1739
+
1709
1740
/// Copies the `src` directory recursively to `dst`. Both are assumed to exist
1710
1741
/// when this function is called. Unwanted files or directories can be skipped
1711
1742
/// by returning `false` from the filter function.
@@ -1751,7 +1782,7 @@ impl Build {
1751
1782
if !src. exists ( ) {
1752
1783
panic ! ( "ERROR: File \" {}\" not found!" , src. display( ) ) ;
1753
1784
}
1754
- self . copy_internal ( src, & dst, true ) ;
1785
+ self . copy_internal ( src, & dst, true , true ) ;
1755
1786
chmod ( & dst, perms) ;
1756
1787
}
1757
1788
0 commit comments