1
1
2
- // FIXME: There is so many PathBuf's in this module
3
- // Conver them to Path
4
-
5
- use std:: path:: { Path , PathBuf } ;
2
+ use std:: path:: Path ;
6
3
use std:: fs;
7
4
use error:: Result ;
8
5
@@ -13,12 +10,12 @@ use regex::Regex;
13
10
/// Target directory must have doc directory.
14
11
///
15
12
/// This function is designed to avoid file duplications.
16
- pub fn copy_doc_dir < P : AsRef < Path > > ( source : P , destination : P ) -> Result < ( ) > {
17
- let destination = destination. as_ref ( ) . to_path_buf ( ) ;
13
+ pub fn copy_doc_dir < P : AsRef < Path > , Q : AsRef < Path > > ( source : P , destination : Q ) -> Result < ( ) > {
14
+ let destination = destination. as_ref ( ) ;
18
15
19
16
// Make sure destination directory exists
20
17
if !destination. exists ( ) {
21
- fs:: create_dir_all ( & destination) ?;
18
+ fs:: create_dir_all ( destination) ?;
22
19
}
23
20
24
21
// Avoid copying common files
@@ -29,8 +26,7 @@ pub fn copy_doc_dir<P: AsRef<Path>>(source: P, destination: P) -> Result<()> {
29
26
for file in source. as_ref ( ) . read_dir ( ) ? {
30
27
31
28
let file = file?;
32
- let mut destination_full_path = PathBuf :: from ( & destination) ;
33
- destination_full_path. push ( file. file_name ( ) ) ;
29
+ let destination_full_path = destination. join ( file. file_name ( ) ) ;
34
30
35
31
let metadata = file. metadata ( ) ?;
36
32
@@ -61,13 +57,18 @@ mod test {
61
57
let destination = tempdir:: TempDir :: new ( "cratesfyi-dst" ) . unwrap ( ) ;
62
58
let doc = source. path ( ) . join ( "doc" ) ;
63
59
fs:: create_dir ( & doc) . unwrap ( ) ;
60
+ fs:: create_dir ( doc. join ( "inner" ) ) . unwrap ( ) ;
64
61
65
62
fs:: write ( doc. join ( "index.html" ) , "<html>spooky</html>" ) . unwrap ( ) ;
66
63
fs:: write ( doc. join ( "index.txt" ) , "spooky" ) . unwrap ( ) ;
64
+ fs:: write ( doc. join ( "inner" ) . join ( "index.html" ) , "<html>spooky</html>" ) . unwrap ( ) ;
65
+ fs:: write ( doc. join ( "inner" ) . join ( "index.txt" ) , "spooky" ) . unwrap ( ) ;
67
66
68
67
// lets try to copy a src directory to tempdir
69
- copy_doc_dir ( source. path ( ) , destination. path ( ) ) . unwrap ( ) ;
68
+ copy_doc_dir ( source. path ( ) . join ( "doc" ) , destination. path ( ) ) . unwrap ( ) ;
70
69
assert ! ( destination. path( ) . join( "index.html" ) . exists( ) ) ;
71
70
assert ! ( !destination. path( ) . join( "index.txt" ) . exists( ) ) ;
71
+ assert ! ( destination. path( ) . join( "inner" ) . join( "index.html" ) . exists( ) ) ;
72
+ assert ! ( !destination. path( ) . join( "inner" ) . join( "index.txt" ) . exists( ) ) ;
72
73
}
73
74
}
0 commit comments