use std::fs;
use std::io;
use std::path::Path;
pub(super) const SLICES: [&str; 2] = ["steps", "inbox"];
pub(super) fn copy_matching(src_root: &Path, dst_root: &Path, agent_id: &str) -> io::Result<()> {
if !src_root.is_dir() {
return Ok(());
}
let prefix = format!("{agent_id}-");
for entry in fs::read_dir(src_root)? {
let entry = entry?;
let name = entry.file_name();
let name_s = name.to_string_lossy();
if *name_s == *agent_id || name_s.starts_with(&prefix) {
copy_entry(&entry.path(), &dst_root.join(&name))?;
}
}
Ok(())
}
pub(super) fn copy_dir_all(src: &Path, dst: &Path) -> io::Result<()> {
fs::create_dir_all(dst)?;
for entry in fs::read_dir(src)? {
let entry = entry?;
copy_entry(&entry.path(), &dst.join(entry.file_name()))?;
}
Ok(())
}
fn copy_entry(src: &Path, dst: &Path) -> io::Result<()> {
if src.is_dir() {
copy_dir_all(src, dst)
} else {
fs::copy(src, dst).map(|_| ())
}
}