|
1 | 1 | #[cfg(test)] |
2 | 2 | use crate::prelude::*; |
| 3 | +use std::io; |
3 | 4 | use std::path::{Path, PathBuf}; |
4 | | -use std::{fs, io}; |
5 | 5 |
|
6 | 6 | pub fn copy_dir_recursively(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> { |
7 | | - fs::create_dir_all(&dst)?; |
8 | | - for entry in fs::read_dir(src)? { |
9 | | - let entry = entry?; |
10 | | - let ty = entry.file_type()?; |
11 | | - let path = entry.path(); |
12 | | - |
13 | | - if ty.is_dir() { |
14 | | - if entry.file_name() == ".git" || entry.file_name() == "target" { |
15 | | - continue; |
16 | | - } |
17 | | - |
18 | | - copy_dir_recursively(&path, dst.as_ref().join(entry.file_name()))?; |
19 | | - } else if ty.is_symlink() { |
20 | | - // Follow symlinks to directories, copy other symlinks as-is |
21 | | - if let Ok(metadata) = fs::metadata(&path) { |
22 | | - if metadata.is_dir() { |
23 | | - // Symlink points to a directory, follow it recursively |
24 | | - copy_dir_recursively(&path, dst.as_ref().join(entry.file_name()))?; |
25 | | - } else { |
26 | | - // Symlink points to a file, copy it |
27 | | - fs::copy(&path, dst.as_ref().join(entry.file_name()))?; |
28 | | - } |
29 | | - } else { |
30 | | - // If metadata fails (broken symlink), copy the symlink as-is |
31 | | - fs::copy(&path, dst.as_ref().join(entry.file_name()))?; |
32 | | - } |
33 | | - } else { |
34 | | - fs::copy(&path, dst.as_ref().join(entry.file_name()))?; |
35 | | - } |
36 | | - } |
| 7 | + let excludes = vec!["node_modules".into(), "target".into()]; |
| 8 | + let includes = vec![]; |
| 9 | + dircpy::copy_dir_advanced(src, dst, true, true, true, excludes, includes)?; |
37 | 10 | Ok(()) |
38 | 11 | } |
39 | 12 |
|
|
0 commit comments