brown/bro/
clone_dir_structure.rs1use crate::BroPath;
2use crate::bro;
3use crate::BrownError;
4use crate::path_exists;
5pub fn clone_dir_structure<'a>(source:&str,destination:&str)
7->Result<Vec<String>,BrownError>{
8match path_exists(source) {
10 true=>{},
11 false=>{return Err(BrownError::DirNotFound)},
12}
13let source_str = bro::
15dir_structure_to_string(source)?;
16
17let bro_path = BroPath::new();
19let paths_changed_parent =
20bro_path.change_destination(&source_str, source, destination)?;
21
22let mutated =
23bro_path.remove_dot_slash_all(&paths_changed_parent)?;
24let mutated_str:Vec<&str> =
26mutated.iter().map(|s| &**s).collect();
27
28let x =
29 bro::create_dir_structure
30 (&mutated_str);
31
32 match x {
33 Ok(_item)=>{
34 Ok(mutated)
35 },
36 Err(e)=>{return Err(e);},
37 }
38}
39
40mod tests {
41use crate::test_helper::TestHelper;
42use super::*;
43use super::super::*;
44#[test]
45fn manual_test(){
46 let th = TestHelper::
47 new("dir963");
48
49 let _ = th.create_parent_dir();
50 let _ = th.create_dir("a");
51 let _ = th.create_dir("a/a1");
52 let _ = th.create_dir("b");
53 let _ = th.create_dir("b/b1");
54
55let final_outcome =
56clone_dir_structure("dir963","dir97")
57.unwrap();
58let compare = [
62 "dir97",
63 "dir97/b",
64 "dir97/a",
65 "dir97/b/b1",
66 "dir97/a/a1",
67 ];
68 assert_eq!(final_outcome,compare);
70 let _ =bro::remove_dir_brute("dir97");
71 let _ = th.tear_down();
72}
73}