Skip to content

Commit fdfb58a

Browse files
muhamadazmyzaibon
authored andcommitted
Support symlinking in bootstrap
1 parent f77f78a commit fdfb58a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

bootstrap/bootstrap/src/zfs.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use failure::Error;
2+
use std::fs;
23
use std::path::{Path, PathBuf};
34
use std::process::{Child, Command};
45
use walkdir::WalkDir;
@@ -66,10 +67,21 @@ impl Zfs {
6667
let mut dst = PathBuf::new();
6768
dst.push(&target);
6869
dst.push(src.strip_prefix(&self.target)?);
69-
if entry.file_type().is_dir() {
70+
71+
let typ = entry.file_type();
72+
if typ.is_dir() {
73+
debug!("creating directory {:?}", dst);
7074
std::fs::create_dir_all(dst)?;
71-
} else {
75+
} else if typ.is_file() {
76+
debug!("installing file {:?}", dst);
7277
std::fs::copy(&src, &dst)?;
78+
} else if typ.is_symlink() {
79+
let _ = fs::remove_file(&dst); // we don't care if file does not exist
80+
let target = fs::read_link(src)?;
81+
debug!("linking file {:?} -> {:?}", dst, target);
82+
std::os::unix::fs::symlink(&dst, target)?;
83+
} else {
84+
error!("unsupported file type: ({:?}): {:?}", src, typ)
7385
}
7486
}
7587

0 commit comments

Comments
 (0)