From fdfb58abd1f7cfa9118fdef757f2d9b722f36f30 Mon Sep 17 00:00:00 2001 From: Muhamad Azamy Date: Thu, 30 Jan 2020 10:54:24 +0200 Subject: [PATCH] Support symlinking in bootstrap --- bootstrap/bootstrap/src/zfs.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bootstrap/bootstrap/src/zfs.rs b/bootstrap/bootstrap/src/zfs.rs index ab2e7a2c4..fb8e842fa 100644 --- a/bootstrap/bootstrap/src/zfs.rs +++ b/bootstrap/bootstrap/src/zfs.rs @@ -1,4 +1,5 @@ use failure::Error; +use std::fs; use std::path::{Path, PathBuf}; use std::process::{Child, Command}; use walkdir::WalkDir; @@ -66,10 +67,21 @@ impl Zfs { let mut dst = PathBuf::new(); dst.push(&target); dst.push(src.strip_prefix(&self.target)?); - if entry.file_type().is_dir() { + + let typ = entry.file_type(); + if typ.is_dir() { + debug!("creating directory {:?}", dst); std::fs::create_dir_all(dst)?; - } else { + } else if typ.is_file() { + debug!("installing file {:?}", dst); std::fs::copy(&src, &dst)?; + } else if typ.is_symlink() { + let _ = fs::remove_file(&dst); // we don't care if file does not exist + let target = fs::read_link(src)?; + debug!("linking file {:?} -> {:?}", dst, target); + std::os::unix::fs::symlink(&dst, target)?; + } else { + error!("unsupported file type: ({:?}): {:?}", src, typ) } }