From 9230733079101494f803915cbf9f904fe3cdc108 Mon Sep 17 00:00:00 2001 From: Aram Drevekenin Date: Mon, 18 Nov 2024 11:23:26 +0100 Subject: [PATCH] feat(plugins): add /cache folder (#3787) * feat(plugins): add /cache folder * style(fmt): rustfmt --- zellij-server/src/plugins/plugin_loader.rs | 17 +++++++++++++++-- zellij-server/src/plugins/plugin_map.rs | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/zellij-server/src/plugins/plugin_loader.rs b/zellij-server/src/plugins/plugin_loader.rs index 32d26dd3..760824d7 100644 --- a/zellij-server/src/plugins/plugin_loader.rs +++ b/zellij-server/src/plugins/plugin_loader.rs @@ -60,6 +60,7 @@ pub struct PluginLoader<'a> { plugin_dir: &'a PathBuf, tab_index: Option, plugin_own_data_dir: PathBuf, + plugin_own_cache_dir: PathBuf, size: Size, wasm_blob_on_hd: Option<(Vec, PathBuf)>, path_to_default_shell: PathBuf, @@ -344,7 +345,10 @@ impl<'a> PluginLoader<'a> { let plugin_own_data_dir = ZELLIJ_SESSION_CACHE_DIR .join(Url::from(&plugin.location).to_string()) .join(format!("{}-{}", plugin_id, client_id)); - create_plugin_fs_entries(&plugin_own_data_dir)?; + let plugin_own_cache_dir = ZELLIJ_SESSION_CACHE_DIR + .join(Url::from(&plugin.location).to_string()) + .join(format!("plugin_cache")); + create_plugin_fs_entries(&plugin_own_data_dir, &plugin_own_cache_dir)?; let plugin_path = plugin.path.clone(); Ok(PluginLoader { plugin_cache: plugin_cache.clone(), @@ -358,6 +362,7 @@ impl<'a> PluginLoader<'a> { plugin_dir, tab_index, plugin_own_data_dir, + plugin_own_cache_dir, size, wasm_blob_on_hd: None, path_to_default_shell, @@ -789,6 +794,7 @@ impl<'a> PluginLoader<'a> { let dirs = vec![ ("/host".to_owned(), self.zellij_cwd.clone()), ("/data".to_owned(), self.plugin_own_data_dir.clone()), + ("/cache".to_owned(), self.plugin_own_cache_dir.clone()), ("/tmp".to_owned(), ZELLIJ_TMP_DIR.clone()), ]; let dirs = dirs.into_iter().filter(|(_dir_name, dir)| { @@ -825,6 +831,7 @@ impl<'a> PluginLoader<'a> { senders: self.senders.clone(), wasi_ctx, plugin_own_data_dir: self.plugin_own_data_dir.clone(), + plugin_own_cache_dir: self.plugin_own_cache_dir.clone(), tab_index: self.tab_index, path_to_default_shell: self.path_to_default_shell.clone(), capabilities: self.capabilities.clone(), @@ -862,13 +869,19 @@ impl<'a> PluginLoader<'a> { } } -fn create_plugin_fs_entries(plugin_own_data_dir: &PathBuf) -> Result<()> { +fn create_plugin_fs_entries( + plugin_own_data_dir: &PathBuf, + plugin_own_cache_dir: &PathBuf, +) -> Result<()> { let err_context = || "failed to create plugin fs entries"; // Create filesystem entries mounted into WASM. // We create them here to get expressive error messages in case they fail. fs::create_dir_all(&plugin_own_data_dir) .with_context(|| format!("failed to create datadir in {plugin_own_data_dir:?}")) .with_context(err_context)?; + fs::create_dir_all(&plugin_own_cache_dir) + .with_context(|| format!("failed to create cache dir in {plugin_own_cache_dir:?}")) + .with_context(err_context)?; fs::create_dir_all(ZELLIJ_TMP_DIR.as_path()) .with_context(|| format!("failed to create tmpdir at {:?}", &ZELLIJ_TMP_DIR.as_path())) .with_context(err_context)?; diff --git a/zellij-server/src/plugins/plugin_map.rs b/zellij-server/src/plugins/plugin_map.rs index 3cda4fc1..655aec50 100644 --- a/zellij-server/src/plugins/plugin_map.rs +++ b/zellij-server/src/plugins/plugin_map.rs @@ -295,6 +295,7 @@ pub struct PluginEnv { pub client_id: ClientId, #[allow(dead_code)] pub plugin_own_data_dir: PathBuf, + pub plugin_own_cache_dir: PathBuf, pub path_to_default_shell: PathBuf, pub capabilities: PluginCapabilities, pub client_attributes: ClientAttributes,