]>
Commit | Line | Data |
---|---|---|
1 | use std::fs::{copy, create_dir_all, read_dir}; | |
2 | use std::io::Result; | |
3 | use std::path::PathBuf; | |
4 | use crate::template::TemplateContext; | |
5 | ||
6 | fn recursively_copy(source: &PathBuf, target: &PathBuf) -> Result<()> { | |
7 | let entries = read_dir(source)?; | |
8 | for entry in entries { | |
9 | let entry = entry?; | |
10 | let entry_type = entry.file_type()?; | |
11 | let entry_name = entry.file_name(); | |
12 | let entry_source = entry.path(); | |
13 | let entry_target = target.join(entry_name); | |
14 | ||
15 | if entry_type.is_dir() { | |
16 | create_dir_all(&entry_target)?; | |
17 | recursively_copy(&entry_source, &entry_target)?; | |
18 | } else { | |
19 | copy(&entry_source, &entry_target)?; | |
20 | } | |
21 | } | |
22 | ||
23 | Ok(()) | |
24 | } | |
25 | ||
26 | pub fn generate(source: &PathBuf, _: &PathBuf, target: &PathBuf, _: &TemplateContext) -> Result<()> { | |
27 | if source.exists() { | |
28 | return recursively_copy(source, target) | |
29 | } | |
30 | Ok(()) | |
31 | } |