1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
extern crate reflink;
#[macro_use] extern crate log;
extern crate env_logger;
use reflink::reflink_or_copy;
use std::convert::AsRef;
use std::fs;
use std::io;
use std::path::Path;
pub fn clonedir<A: AsRef<Path>, B: AsRef<Path>>(from: A, to: B) -> io::Result<()> {
let from = from.as_ref();
let to = to.as_ref();
debug!("cloning dir {:?} to {:?}", &from, &to);
for f in fs::read_dir(from)?.into_iter().map(|f| f.unwrap().path()) {
fs::create_dir_all(&to)?;
if f.is_dir() {
clonedir(&f, &to)?;
} else if f.is_file() {
debug!("cloning {:?} to {:?}", &f, &to);
reflink_or_copy(&f, to.join(f.file_name().unwrap()))?;
}
}
Ok(())
}