Skip to content

Commit 152bc3b

Browse files
committed
chore: use dircpy crate to copy folders
1 parent fb0b65f commit 152bc3b

3 files changed

Lines changed: 131 additions & 31 deletions

File tree

‎Cargo.lock‎

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎go-runner/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ statrs = { version = "0.18", default-features = false }
2121
thiserror = "2.0"
2222
tempfile = "3.14"
2323
semver = "1.0.27"
24+
dircpy = "0.3.19"
2425

2526
[dev-dependencies]
2627
divan = { version = "4.1.0", package = "codspeed-divan-compat" }

‎go-runner/src/utils.rs‎

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,12 @@
11
#[cfg(test)]
22
use crate::prelude::*;
3+
use std::io;
34
use std::path::{Path, PathBuf};
4-
use std::{fs, io};
55

66
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)?;
3710
Ok(())
3811
}
3912

0 commit comments

Comments
 (0)