]> git.r.bdr.sh - rbdr/blog/blame_incremental - src/utils.rs
Generate and archive blog, allow publishing
[rbdr/blog] / src / utils.rs
... / ...
CommitLineData
1use std::io::Result;
2use std::path::PathBuf;
3use std::fs::{copy, create_dir_all, read_dir};
4
5pub fn recursively_copy(source: &PathBuf, target: &PathBuf) -> Result<()> {
6 let entries = read_dir(source)?;
7 for entry in entries {
8 let entry = entry?;
9 let entry_type = entry.file_type()?;
10 let entry_name = entry.file_name();
11 let entry_source = entry.path();
12 let entry_target = target.join(entry_name);
13
14 if entry_type.is_dir() {
15 create_dir_all(&entry_target)?;
16 recursively_copy(&entry_source, &entry_target)?;
17 } else {
18 copy(&entry_source, &entry_target)?;
19 }
20 }
21
22 Ok(())
23}