diff --git a/coffee_core/src/coffee.rs b/coffee_core/src/coffee.rs index d8ded7c..1f0f01c 100644 --- a/coffee_core/src/coffee.rs +++ b/coffee_core/src/coffee.rs @@ -271,6 +271,12 @@ impl PluginManager for CoffeeManager { if let Some(mut plugin) = repo.get_plugin_by_name(plugin) { log::trace!("{:?}", plugin); + if try_dynamic && plugin.important() { + return Err(error!( + "plugin is important, can't be dynamically installed" + )); + } + // old_root_path is the path where the plugin is cloned and currently stored // eg. ~/.coffee/repositories// let old_root_path = plugin.root_path.clone(); @@ -297,6 +303,12 @@ impl PluginManager for CoffeeManager { ); let old_exec_path = plugin.exec_path.clone(); + let plugin_conf_key = if plugin.important() { + "important-plugin" + } else { + "plugin" + }; + match old_exec_path.strip_prefix(&old_root_path) { Some(relative_path) => { let new_exec_path = format!("{}{}", new_root_path, relative_path); @@ -312,7 +324,7 @@ impl PluginManager for CoffeeManager { self.config.plugins.push(plugin); log::debug!("path coffee conf: {}", self.coffee_cln_config.path); self.coffee_cln_config - .add_conf("plugin", &path.to_owned()) + .add_conf(plugin_conf_key, &path.to_owned()) .map_err(|err| error!("{}", err.cause))?; log::debug!("coffee conf updated: {}", self.coffee_cln_config); self.flush().await?; @@ -348,9 +360,14 @@ impl PluginManager for CoffeeManager { log::debug!("runnable plugin path: {exec_path}"); plugins.remove(index); log::debug!("coffee cln config: {}", self.coffee_cln_config); + let plugin_conf_key = if plugin.important() { + "important-plugin" + } else { + "plugin" + }; let remove_config = self .coffee_cln_config - .rm_conf("plugin", Some(&exec_path.to_owned())); + .rm_conf(plugin_conf_key, Some(&exec_path.to_owned())); if let Err(err) = remove_config { // if this is true, we are probably a dynamic plugin: if err.cause.contains("field with `plugin` not present") { diff --git a/coffee_lib/src/plugin.rs b/coffee_lib/src/plugin.rs index 1123c42..873fa66 100644 --- a/coffee_lib/src/plugin.rs +++ b/coffee_lib/src/plugin.rs @@ -165,6 +165,18 @@ impl Plugin { pub fn tipping_info(&self) -> Option { self.conf.as_ref().and_then(|conf| conf.tipping.clone()) } + + pub fn important(&self) -> bool { + if let Some(config) = &self.conf { + if let Some(important) = config.plugin.important { + important + } else { + false + } + } else { + false + } + } } impl fmt::Display for Plugin { diff --git a/coffee_lib/src/plugin_conf.rs b/coffee_lib/src/plugin_conf.rs index b241c6b..0df276d 100644 --- a/coffee_lib/src/plugin_conf.rs +++ b/coffee_lib/src/plugin_conf.rs @@ -16,6 +16,7 @@ pub struct Plugin { pub dependencies: Option>, pub install: Option, pub main: String, + pub important: Option, } #[derive(Debug, PartialEq, Serialize, Deserialize)] diff --git a/docs/docs-book/src/support-coffee.md b/docs/docs-book/src/support-coffee.md index 27b92f6..30c71a2 100644 --- a/docs/docs-book/src/support-coffee.md +++ b/docs/docs-book/src/support-coffee.md @@ -35,6 +35,7 @@ Where it is possible to specify the following options: - `lang`: the language of the plugin, used to try to install a plugin when the `install` script is not specified; - `install`: a custom install script used by Coffee to compile the plugin; - `main`: the binary or runnable file that core lightning needs to run. +- `important`: bool flag for plugins that must be run as important-plugin In the future, the coffee will be also able to install `binary` other than a `plugin`, so coffee will be installed with coffee itself. With some craziness will be also possible to manage core lightning itself.