| 551 | } |
| 552 | |
| 553 | pub fn copy_folder_content( |
| 554 | source: impl AsRef<Path>, |
| 555 | destination: impl AsRef<Path>, |
| 556 | single_file: Option<String>, |
| 557 | avoid_path: &PathBuf, |
| 558 | log: &Logger, |
| 559 | ) -> io::Result<()> { |
| 560 | fs::create_dir_all(&destination)?; |
| 561 | for dir_entry in fs::read_dir(source)? { |
| 562 | let entry = dir_entry?; |
| 563 | let file_type = entry.file_type()?; |
| 564 | let destination_path = destination.as_ref().join(entry.file_name()); |
| 565 | if file_type.is_file() { |
| 566 | if entry.path().eq(avoid_path) { |
| 567 | continue; |
| 568 | } |
| 569 | let target_file_name = entry |
| 570 | .file_name() |
| 571 | .to_os_string() |
| 572 | .into_string() |
| 573 | .unwrap_or_default(); |
| 574 | if single_file.is_none() |
| 575 | || (single_file.is_some() && single_file.clone().unwrap().eq(&target_file_name)) |
| 576 | { |
| 577 | log.trace(format!( |
| 578 | "Copying {} to {}", |
| 579 | entry.path().display(), |
| 580 | destination_path.display() |
| 581 | )); |
| 582 | if !destination_path.exists() { |
| 583 | fs::copy(entry.path(), destination_path)?; |
| 584 | } |
| 585 | } |
| 586 | } else if single_file.is_none() { |
| 587 | copy_folder_content( |
| 588 | entry.path(), |
| 589 | destination_path, |
| 590 | single_file.clone(), |
| 591 | avoid_path, |
| 592 | log, |
| 593 | )?; |
| 594 | } |
| 595 | } |
| 596 | Ok(()) |
| 597 | } |
| 598 | |
| 599 | pub fn default_cache_folder() -> PathBuf { |
| 600 | if let Some(base_dirs) = BaseDirs::new() { |