]>
Commit | Line | Data |
---|---|---|
136023e0 XL |
1 | use std::fs; |
2 | use std::path::Path; | |
3 | use std::process::{self, Command}; | |
4 | ||
5 | #[track_caller] | |
6 | pub(crate) fn try_hard_link(src: impl AsRef<Path>, dst: impl AsRef<Path>) { | |
7 | let src = src.as_ref(); | |
8 | let dst = dst.as_ref(); | |
9 | if let Err(_) = fs::hard_link(src, dst) { | |
10 | fs::copy(src, dst).unwrap(); // Fallback to copying if hardlinking failed | |
11 | } | |
12 | } | |
13 | ||
14 | #[track_caller] | |
15 | pub(crate) fn spawn_and_wait(mut cmd: Command) { | |
16 | if !cmd.spawn().unwrap().wait().unwrap().success() { | |
17 | process::exit(1); | |
18 | } | |
19 | } | |
20 | ||
21 | pub(crate) fn copy_dir_recursively(from: &Path, to: &Path) { | |
22 | for entry in fs::read_dir(from).unwrap() { | |
23 | let entry = entry.unwrap(); | |
24 | let filename = entry.file_name(); | |
25 | if filename == "." || filename == ".." { | |
26 | continue; | |
27 | } | |
28 | if entry.metadata().unwrap().is_dir() { | |
29 | fs::create_dir(to.join(&filename)).unwrap(); | |
30 | copy_dir_recursively(&from.join(&filename), &to.join(&filename)); | |
31 | } else { | |
32 | fs::copy(from.join(&filename), to.join(&filename)).unwrap(); | |
33 | } | |
34 | } | |
35 | } |