fix(wasm_vm): use cache_dirs for ephemeral plugin data (#1230)

fix(wasm_vm): use `cache_dirs` for ephemeral plugin data

Use proper `cache_directories` by default, that users can be expected
to have proper write permissions for.

The directory is used for plugin hashes, and compilation data.
This commit is contained in:
a-kenji 2022-03-17 11:57:38 +01:00 committed by GitHub
parent 19b74e073a
commit 092926c5d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 21 deletions

View file

@ -29,7 +29,7 @@ use crate::{
};
use zellij_utils::{
consts::{VERSION, ZELLIJ_PROJ_DIR, ZELLIJ_TMP_DIR},
consts::{VERSION, ZELLIJ_CACHE_DIR, ZELLIJ_PROJ_DIR, ZELLIJ_TMP_DIR},
errors::{ContextType, PluginContext},
};
use zellij_utils::{
@ -106,14 +106,7 @@ pub(crate) fn wasm_thread_main(
.unwrap_or_else(|| panic!("Plugin {:?} could not be resolved", run));
let (instance, plugin_env) = start_plugin(
plugin_id,
client_id,
&plugin,
tab_index,
&bus,
&store,
&data_dir,
&plugin_global_data_dir,
plugin_id, client_id, &plugin, tab_index, &bus, &store, &data_dir,
);
let mut main_user_instance = instance.clone();
@ -204,16 +197,8 @@ pub(crate) fn wasm_thread_main(
// load headless plugins
for plugin in plugins.iter() {
if let PluginType::Headless = plugin.run {
let (instance, plugin_env) = start_plugin(
plugin_id,
client_id,
plugin,
0,
&bus,
&store,
&data_dir,
&plugin_global_data_dir,
);
let (instance, plugin_env) =
start_plugin(plugin_id, client_id, plugin, 0, &bus, &store, &data_dir);
headless_plugins.insert(plugin_id, (instance, plugin_env));
plugin_id += 1;
}
@ -238,7 +223,6 @@ fn start_plugin(
bus: &Bus<PluginInstruction>,
store: &Store,
data_dir: &Path,
plugin_global_data_dir: &Path,
) -> (Instance, PluginEnv) {
if plugin._allow_exec_host_cmd {
info!(
@ -271,7 +255,7 @@ fn start_plugin(
let output = Pipe::new();
let input = Pipe::new();
let stderr = LoggingPipe::new(&plugin.location.to_string(), plugin_id);
let plugin_own_data_dir = plugin_global_data_dir.join(Url::from(&plugin.location).to_string());
let plugin_own_data_dir = ZELLIJ_CACHE_DIR.join(Url::from(&plugin.location).to_string());
fs::create_dir_all(&plugin_own_data_dir).unwrap_or_else(|e| {
log::error!(
"Could not create plugin_own_data_dir in {:?} \n Error: {:?}",

View file

@ -53,6 +53,7 @@ lazy_static! {
pub static ref ZELLIJ_TMP_DIR: PathBuf = PathBuf::from(format!("/tmp/zellij-{}", *UID));
pub static ref ZELLIJ_TMP_LOG_DIR: PathBuf = ZELLIJ_TMP_DIR.join("zellij-log");
pub static ref ZELLIJ_TMP_LOG_FILE: PathBuf = ZELLIJ_TMP_LOG_DIR.join("zellij.log");
pub static ref ZELLIJ_CACHE_DIR: PathBuf = ZELLIJ_PROJ_DIR.cache_dir().to_path_buf();
}
pub const FEATURES: &[&str] = &[