@@ -1668,10 +1668,23 @@ impl Build {
16681668     /// You can neither rely on this being a copy nor it being a link, 
16691669     /// so do not write to dst. 
16701670     pub  fn  copy_link ( & self ,  src :  & Path ,  dst :  & Path )  { 
1671-         self . copy_link_internal ( src,  dst,  false ) ; 
1671+         self . copy_internal ( src,  dst,  false ,   true ) ; 
16721672    } 
16731673
1674-     fn  copy_link_internal ( & self ,  src :  & Path ,  dst :  & Path ,  dereference_symlinks :  bool )  { 
1674+     /// Links a file from `src` to `dst`. 
1675+      /// Unlike, [`Build::copy_link`], this makes an actual copy, which is usually not required, 
1676+      /// so `copy_link` should be used instead if possible. 
1677+      pub  fn  copy ( & self ,  src :  & Path ,  dst :  & Path )  { 
1678+         self . copy_internal ( src,  dst,  false ,  false ) ; 
1679+     } 
1680+ 
1681+     fn  copy_internal ( 
1682+         & self , 
1683+         src :  & Path , 
1684+         dst :  & Path , 
1685+         dereference_symlinks :  bool , 
1686+         link_if_possible :  bool , 
1687+     )  { 
16751688        if  self . config . dry_run ( )  { 
16761689            return ; 
16771690        } 
@@ -1691,7 +1704,7 @@ impl Build {
16911704                return ; 
16921705            } 
16931706        } 
1694-         if  let   Ok ( ( ) )  =  fs:: hard_link ( & src,  dst)  { 
1707+         if  link_if_possible &&  fs:: hard_link ( & src,  dst) . is_ok ( )  { 
16951708            // Attempt to "easy copy" by creating a hard link 
16961709            // (symlinks don't work on windows), but if that fails 
16971710            // just fall back to a slow `copy` operation. 
@@ -1726,6 +1739,28 @@ impl Build {
17261739        } 
17271740    } 
17281741
1742+     /// Copies the `src` directory recursively to `dst`. Both are assumed to exist 
1743+      /// when this function is called. 
1744+      /// Unlike, [`Build::cp_link_r`], this makes an actual copy, which is usually not required, 
1745+      /// so `cp_link_r` should be used instead if possible. 
1746+      pub  fn  cp_r ( & self ,  src :  & Path ,  dst :  & Path )  { 
1747+         if  self . config . dry_run ( )  { 
1748+             return ; 
1749+         } 
1750+         for  f in  self . read_dir ( src)  { 
1751+             let  path = f. path ( ) ; 
1752+             let  name = path. file_name ( ) . unwrap ( ) ; 
1753+             let  dst = dst. join ( name) ; 
1754+             if  t ! ( f. file_type( ) ) . is_dir ( )  { 
1755+                 t ! ( fs:: create_dir_all( & dst) ) ; 
1756+                 self . cp_r ( & path,  & dst) ; 
1757+             }  else  { 
1758+                 let  _ = fs:: remove_file ( & dst) ; 
1759+                 self . copy ( & path,  & dst) ; 
1760+             } 
1761+         } 
1762+     } 
1763+ 
17291764    /// Copies the `src` directory recursively to `dst`. Both are assumed to exist 
17301765     /// when this function is called. 
17311766     /// Will attempt to use hard links if possible and fall back to copying. 
@@ -1779,7 +1814,9 @@ impl Build {
17791814        if  !src. exists ( )  { 
17801815            panic ! ( "ERROR: File \" {}\"  not found!" ,  src. display( ) ) ; 
17811816        } 
1782-         self . copy_link_internal ( src,  & dst,  true ) ; 
1817+ 
1818+         self . copy_internal ( src,  & dst,  true ,  true ) ; 
1819+ 
17831820        chmod ( & dst,  perms) ; 
17841821    } 
17851822
0 commit comments