(from: &Path, to: &Path, exclude_j2_files: bool)
| 15 | use walkdir::WalkDir; |
| 16 | |
| 17 | pub fn copy_files(from: &Path, to: &Path, exclude_j2_files: bool) -> Result<(), Error> { |
| 18 | let files = WalkDir::new(from).follow_links(true).into_iter().filter_map(|e| e.ok()); |
| 19 | |
| 20 | let files = match exclude_j2_files { |
| 21 | true => files |
| 22 | .filter(|e| { |
| 23 | // return only non *.j2.* files |
| 24 | e.file_name().to_str().map(|s| !s.contains(".j2.")).unwrap_or(false) |
| 25 | }) |
| 26 | .collect::<Vec<_>>(), |
| 27 | false => files.collect::<Vec<_>>(), |
| 28 | }; |
| 29 | |
| 30 | create_dir_all(to)?; |
| 31 | let from_str = from.to_string_lossy(); |
| 32 | |
| 33 | for file in files { |
| 34 | let path_str = file.path().to_string_lossy(); |
| 35 | let dest = format!( |
| 36 | "{}{}", |
| 37 | to.to_str().unwrap_or(""), |
| 38 | path_str.replace(from_str.as_ref(), "").as_str() |
| 39 | ); |
| 40 | |
| 41 | if file.metadata()?.is_dir() { |
| 42 | create_dir_all(&dest)?; |
| 43 | } |
| 44 | |
| 45 | let _ = fs::copy(file.path(), dest); |
| 46 | } |
| 47 | |
| 48 | Ok(()) |
| 49 | } |
| 50 | |
| 51 | pub fn root_workspace_directory<X, S>(working_root_dir: X, execution_id: S) -> Result<PathBuf, Error> |
| 52 | where |
no test coverage detected