diff --git a/components/core/src/fs.rs b/components/core/src/fs.rs index 90c37d2..0355f03 100644 --- a/components/core/src/fs.rs +++ b/components/core/src/fs.rs @@ -249,6 +249,11 @@ pub fn svc_config_path>(service_name: T) -> PathBuf { svc_path(service_name).join("config") } +/// Returns the path to the install configuration directory for a given service. +pub fn svc_config_install_path>(service_name: T) -> PathBuf { + svc_path(service_name).join("config_install") +} + /// Returns the path to a given service's data. pub fn svc_data_path>(service_name: T) -> PathBuf { svc_path(service_name).join("data") @@ -366,6 +371,7 @@ impl<'a> SvcDir<'a> { /// instead. fn create_all_svc_owned_dirs(&self) -> Result<()> { self.create_svc_owned_dir(svc_config_path(&self.service_name))?; + self.create_svc_owned_dir(svc_config_install_path(&self.service_name))?; self.create_svc_owned_dir(svc_data_path(&self.service_name))?; self.create_svc_owned_dir(svc_files_path(&self.service_name))?; self.create_svc_owned_dir(svc_var_path(&self.service_name))?; diff --git a/components/core/src/templating/config.rs b/components/core/src/templating/config.rs index c3d8254..23ac064 100644 --- a/components/core/src/templating/config.rs +++ b/components/core/src/templating/config.rs @@ -484,8 +484,9 @@ impl CfgRenderer { /// Compile and write all configuration files to the configuration directory. /// /// Returns `true` if the configuration has changed. - pub fn compile(&self, service_group_name: &str, pkg: &Pkg, ctx: &T) -> Result + pub fn compile(&self, service_group_name: &str, pkg: &Pkg, render_path: P, ctx: &T) -> Result where + P: AsRef, T: Serialize, { // JW TODO: This function is loaded with IO errors that will be converted a Supervisor @@ -497,7 +498,7 @@ impl CfgRenderer { for (template, _) in self.0.get_templates() { let compiled = self.0.render(&template, ctx)?; let compiled_hash = crypto::hash::hash_string(&compiled); - let cfg_dest = pkg.svc_config_path.join(&template); + let cfg_dest = render_path.as_ref().join(&template); let file_hash = match crypto::hash::hash_file(&cfg_dest) { Ok(file_hash) => file_hash, Err(e) => { diff --git a/components/core/src/templating/mod.rs b/components/core/src/templating/mod.rs index 74c7c5d..4a399c0 100644 --- a/components/core/src/templating/mod.rs +++ b/components/core/src/templating/mod.rs @@ -34,20 +34,21 @@ use templating::hooks::{Hook, InstallHook}; pub use self::context::RenderContext; -pub fn compile_from_package_install(package: &PackageInstall) -> Result<()> { +pub fn compile_for_package_install(package: &PackageInstall) -> Result<()> { let pkg = package::Pkg::from_install(package.clone())?; fs::SvcDir::new(&pkg.name, &pkg.svc_user, &pkg.svc_group).create()?; let cfg = config::Cfg::new(&pkg, None)?; let ctx = RenderContext::new(&pkg, &cfg); - let cfg_renderer = config::CfgRenderer::new(pkg.path.join("config"))?; - cfg_renderer.compile(&pkg.name, &pkg, &ctx)?; + let cfg_renderer = config::CfgRenderer::new(pkg.path.join("config_install"))?; + cfg_renderer.compile(&pkg.name, &pkg, &pkg.svc_config_install_path, &ctx)?; if let Some(ref hook) = InstallHook::load( &pkg.name, - &package.installed_path.join("hooks"), - &fs::svc_hooks_path(&pkg.name)) { + &fs::svc_hooks_path(&pkg.name), + &package.installed_path.join("hooks")) { + println!("compiling install hook"); hook.compile(&pkg.name, &ctx)?; }; @@ -391,25 +392,25 @@ test: something"# let hooks_path = root.join("hooks"); std::fs::create_dir_all(&hooks_path).unwrap(); create_with_content( - hooks_path.join("init"), - &String::from("init message is {{cfg.message}}"), + hooks_path.join("install"), + &String::from("install message is {{cfg.message}}"), ); - let config_path = root.join("config"); + let config_path = root.join("config_install"); std::fs::create_dir_all(&config_path).unwrap(); create_with_content( config_path.join("config.txt"), &String::from("config message is {{cfg.message}}"), ); - compile_from_package_install(&pkg_install).expect("compile package"); + compile_for_package_install(&pkg_install).expect("compile package"); assert_eq!( - file_content(fs::svc_config_path(&pkg_install.ident().name).join("config.txt")), + file_content(fs::svc_config_install_path(&pkg_install.ident().name).join("config.txt")), "config message is Hello" ); assert_eq!( - file_content(fs::svc_hooks_path(&pkg_install.ident().name).join("init")), - "init message is Hello" + file_content(fs::svc_hooks_path(&pkg_install.ident().name).join("install")), + "install message is Hello" ); env::remove_var(fs::FS_ROOT_ENVVAR); diff --git a/components/core/src/templating/package.rs b/components/core/src/templating/package.rs index ea988ae..dfdecb6 100644 --- a/components/core/src/templating/package.rs +++ b/components/core/src/templating/package.rs @@ -91,6 +91,7 @@ pub struct Pkg { pub path: PathBuf, pub svc_path: PathBuf, pub svc_config_path: PathBuf, + pub svc_config_install_path: PathBuf, pub svc_data_path: PathBuf, pub svc_files_path: PathBuf, pub svc_static_path: PathBuf, @@ -107,6 +108,7 @@ impl Pkg { let pkg = Pkg { svc_path: fs::svc_path(&package.ident.name), svc_config_path: fs::svc_config_path(&package.ident.name), + svc_config_install_path: fs::svc_config_install_path(&package.ident.name), svc_data_path: fs::svc_data_path(&package.ident.name), svc_files_path: fs::svc_files_path(&package.ident.name), svc_run: fs::svc_path(&package.ident.name).join("run"), @@ -172,6 +174,7 @@ impl<'a> Serialize for PkgProxy<'a> { strukt.serialize_field("path", &p.path)?; strukt.serialize_field("svc_path", &p.svc_path)?; strukt.serialize_field("svc_config_path", &p.svc_config_path)?; + strukt.serialize_field("svc_config_install_path", &p.svc_config_install_path)?; strukt.serialize_field("svc_data_path", &p.svc_data_path)?; strukt.serialize_field("svc_files_path", &p.svc_files_path)?; strukt.serialize_field("svc_static_path", &p.svc_static_path)?;