@@ -8,16 +8,44 @@ use error::Result;
88
99use regex:: Regex ;
1010
11+
12+ /// Copies files from source directory to destination directory.
13+ pub fn copy_dir < P : AsRef < Path > > ( source : P , destination : P ) -> Result < ( ) > {
14+ copy_files_and_handle_html ( source. as_ref ( ) . to_path_buf ( ) ,
15+ destination. as_ref ( ) . to_path_buf ( ) ,
16+ false ,
17+ "" )
18+ }
19+
20+
1121/// Copies documentation from a crate's target directory to destination.
1222///
1323/// Target directory must have doc directory.
1424///
15- /// This function is designed to avoid file duplications.
16- pub fn copy_doc_dir < P : AsRef < Path > > ( target : P , destination : P ) -> Result < ( ) > {
25+ /// This function is designed to avoid file duplications. It is using rustc version string
26+ /// to rename common files (css files, jquery.js, playpen.js, main.js etc.) in a standard rustdoc.
27+ pub fn copy_doc_dir < P : AsRef < Path > > ( target : P ,
28+ destination : P ,
29+ rustc_version : & str )
30+ -> Result < ( ) > {
1731 let source = PathBuf :: from ( target. as_ref ( ) ) . join ( "doc" ) ;
18- let destination = destination. as_ref ( ) . to_path_buf ( ) ;
32+ copy_files_and_handle_html ( source,
33+ destination. as_ref ( ) . to_path_buf ( ) ,
34+ true ,
35+ rustc_version)
36+ }
1937
20- // Make sure destination directory exists
38+
39+ fn copy_files_and_handle_html ( source : PathBuf ,
40+ destination : PathBuf ,
41+ handle_html : bool ,
42+ rustc_version : & str )
43+ -> Result < ( ) > {
44+
45+ // FIXME: handle_html is useless since we started using --resource-suffix
46+ // argument with rustdoc
47+
48+ // Make sure destination directory is exists
2149 if !destination. exists ( ) {
2250 fs:: create_dir_all ( & destination) ?;
2351 }
@@ -37,8 +65,11 @@ pub fn copy_doc_dir<P: AsRef<Path>>(target: P, destination: P) -> Result<()> {
3765
3866 if metadata. is_dir ( ) {
3967 fs:: create_dir_all ( & destination_full_path) ?;
40- copy_doc_dir ( file. path ( ) , destination_full_path) ?
41- } else if dup_regex. is_match ( & file. file_name ( ) . into_string ( ) . unwrap ( ) [ ..] ) {
68+ copy_files_and_handle_html ( file. path ( ) ,
69+ destination_full_path,
70+ handle_html,
71+ & rustc_version) ?
72+ } else if handle_html && dup_regex. is_match ( & file. file_name ( ) . into_string ( ) . unwrap ( ) [ ..] ) {
4273 continue ;
4374 } else {
4475 fs:: copy ( & file. path ( ) , & destination_full_path) ?;
@@ -54,21 +85,19 @@ pub fn copy_doc_dir<P: AsRef<Path>>(target: P, destination: P) -> Result<()> {
5485mod test {
5586 extern crate env_logger;
5687 use std:: fs;
88+ use std:: path:: Path ;
5789 use super :: * ;
5890
5991 #[ test]
60- fn test_copy_doc_dir ( ) {
61- let source = tempdir:: TempDir :: new ( "cratesfyi-src" ) . unwrap ( ) ;
62- let destination = tempdir:: TempDir :: new ( "cratesfyi-dst" ) . unwrap ( ) ;
63- let doc = source. path ( ) . join ( "doc" ) ;
64- fs:: create_dir ( & doc) . unwrap ( ) ;
65-
66- fs:: write ( doc. join ( "index.html" ) , "<html>spooky</html>" ) . unwrap ( ) ;
67- fs:: write ( doc. join ( "index.txt" ) , "spooky" ) . unwrap ( ) ;
92+ #[ ignore]
93+ fn test_copy_dir ( ) {
94+ let destination = tempdir:: TempDir :: new ( "cratesfyi" ) . unwrap ( ) ;
6895
6996 // lets try to copy a src directory to tempdir
70- copy_doc_dir ( source. path ( ) , destination. path ( ) ) . unwrap ( ) ;
71- assert ! ( destination. path( ) . join( "index.html" ) . exists( ) ) ;
72- assert ! ( !destination. path( ) . join( "index.txt" ) . exists( ) ) ;
97+ let res = copy_dir ( Path :: new ( "src" ) , destination. path ( ) ) ;
98+ // remove temp dir
99+ fs:: remove_dir_all ( destination. path ( ) ) . unwrap ( ) ;
100+
101+ assert ! ( res. is_ok( ) ) ;
73102 }
74103}
0 commit comments