From 39f08615d8c5b825b2dbec2f594342cf5fb87f12 Mon Sep 17 00:00:00 2001 From: Mutzi Date: Mon, 30 Jan 2023 17:31:31 +0100 Subject: [PATCH] Fixed directory copy again, added on_install config --- src/config.rs | 1 + src/operations.rs | 19 +++++++++++++------ src/utils.rs | 1 + 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index f2f3254..822487c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -5,6 +5,7 @@ use serde::Deserialize; pub struct Module { #[serde(default)] pub ignore: Vec, + pub on_install: Option, pub content: HashMap } diff --git a/src/operations.rs b/src/operations.rs index 2630086..e206a85 100644 --- a/src/operations.rs +++ b/src/operations.rs @@ -9,9 +9,9 @@ impl ToString for NamedModule { } } -fn install_mod(m: NamedModule) { +fn install_mod(m: &NamedModule) { println!("Installing module {}...", m.0); - 'content_iter: for entry in m.1.content { + 'content_iter: for entry in &m.1.content { let src = std::path::Path::new("repo").join(&entry.0); if src.is_file() { if let Err(err) = std::fs::copy(src, entry.1) { @@ -40,9 +40,9 @@ fn install_mod(m: NamedModule) { } } -fn collect_mod(m: NamedModule) { +fn collect_mod(m: &NamedModule) { println!("Collecting module {}...", m.0); - 'content_iter: for entry in m.1.content { + 'content_iter: for entry in &m.1.content { let dst = std::path::Path::new("repo").join(entry.0.as_str()); let src = std::path::Path::new(entry.1.as_str()); if src.is_file() { @@ -78,7 +78,14 @@ pub fn install(config: &ModToml) { ); for m in to_install { - install_mod(m); + install_mod(&m); + + if let Some(on_install) = &m.1.on_install { + match std::process::Command::new("sh").arg("-c").arg(on_install).status() { + Ok(status) => println!("Install command exited with {status}"), + Err(err) => println!("Failed to execute on install command '{on_install}' with error:\n{err}") + } + } } } @@ -89,7 +96,7 @@ pub fn collect(config: &ModToml) { ); for m in to_collect { - collect_mod(m); + collect_mod(&m); } } diff --git a/src/utils.rs b/src/utils.rs index 22f6d40..ffa13f3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -59,6 +59,7 @@ pub fn copy_dir(src_dir: &Path, dst_dir: &Path, ignored: &[String], pb: &indicat let DirContent { dirs, files } = get_dir_content_filtered(src_dir, ignored, pb)?; + std::fs::create_dir_all(dst_dir).map_err(|e| e.to_string())?; for dir in dirs.into_iter().filter_map(trim_fn) { std::fs::create_dir_all(dst_dir.join(dir)).map_err(|e| e.to_string())?; pb.inc(1);