summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Linford <tlinford@users.noreply.github.com>2023-10-12 09:55:27 +0200
committerGitHub <noreply@github.com>2023-10-12 09:55:27 +0200
commitfb1af39acaa6e00c4bee07bafc35c60a7915164e (patch)
treee0660105f2b03044cee7ed85a210a10261b5f9c7
parentefca21a6ed4ab79396cef3b62a2ba615e9748bfc (diff)
fix(plugins): add zellij version to cached artifact path (#2836)
- move plugin artifact dir to version specific subfolder - also move stdin-cache file to same subfolder, and use a constant for the path
-rw-r--r--zellij-client/src/stdin_ansi_parser.rs17
-rw-r--r--zellij-server/src/plugins/plugin_loader.rs5
-rw-r--r--zellij-utils/src/consts.rs3
3 files changed, 13 insertions, 12 deletions
diff --git a/zellij-client/src/stdin_ansi_parser.rs b/zellij-client/src/stdin_ansi_parser.rs
index 4891c4f73..a34eac5be 100644
--- a/zellij-client/src/stdin_ansi_parser.rs
+++ b/zellij-client/src/stdin_ansi_parser.rs
@@ -1,15 +1,14 @@
use std::time::{Duration, Instant};
-use zellij_utils::consts::{VERSION, ZELLIJ_CACHE_DIR};
const STARTUP_PARSE_DEADLINE_MS: u64 = 500;
use zellij_utils::{
- ipc::PixelDimensions, lazy_static::lazy_static, pane_size::SizeInPixels, regex::Regex,
+ consts::ZELLIJ_STDIN_CACHE_FILE, ipc::PixelDimensions, lazy_static::lazy_static,
+ pane_size::SizeInPixels, regex::Regex,
};
use serde::{Deserialize, Serialize};
use std::fs::{File, OpenOptions};
use std::io::{Read, Write};
-use std::path::PathBuf;
use zellij_utils::anyhow::Result;
#[derive(Debug)]
@@ -77,8 +76,10 @@ impl StdinAnsiParser {
self.drain_pending_events()
}
pub fn read_cache(&self) -> Option<Vec<AnsiStdinInstruction>> {
- let path = self.cache_dir_path();
- match OpenOptions::new().read(true).open(path.as_path()) {
+ match OpenOptions::new()
+ .read(true)
+ .open(ZELLIJ_STDIN_CACHE_FILE.as_path())
+ {
Ok(mut file) => {
let mut json_cache = String::new();
file.read_to_string(&mut json_cache).ok()?;
@@ -97,9 +98,8 @@ impl StdinAnsiParser {
}
}
pub fn write_cache(&self, events: Vec<AnsiStdinInstruction>) {
- let path = self.cache_dir_path();
if let Ok(serialized_events) = serde_json::to_string(&events) {
- if let Ok(mut file) = File::create(path.as_path()) {
+ if let Ok(mut file) = File::create(ZELLIJ_STDIN_CACHE_FILE.as_path()) {
let _ = file.write_all(serialized_events.as_bytes());
}
};
@@ -134,9 +134,6 @@ impl StdinAnsiParser {
self.raw_buffer.push(byte);
}
}
- fn cache_dir_path(&self) -> PathBuf {
- ZELLIJ_CACHE_DIR.join(&format!("zellij-stdin-cache-v{}", VERSION))
- }
}
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/zellij-server/src/plugins/plugin_loader.rs b/zellij-server/src/plugins/plugin_loader.rs
index 3158610b9..4d551e383 100644
--- a/zellij-server/src/plugins/plugin_loader.rs
+++ b/zellij-server/src/plugins/plugin_loader.rs
@@ -14,6 +14,7 @@ use std::{
use url::Url;
use wasmer::{AsStoreRef, Instance, Module, Store};
use wasmer_wasi::{Pipe, WasiState};
+use zellij_utils::consts::ZELLIJ_PLUGIN_ARTIFACT_DIR;
use zellij_utils::prost::Message;
use crate::{
@@ -521,7 +522,7 @@ impl<'a> PluginLoader<'a> {
let (wasm_bytes, cached_path) = self.plugin_bytes_and_cache_path()?;
let timer = std::time::Instant::now();
let err_context = || "failed to recover cache dir";
- let module = fs::create_dir_all(ZELLIJ_CACHE_DIR.to_owned())
+ let module = fs::create_dir_all(ZELLIJ_PLUGIN_ARTIFACT_DIR.as_path())
.map_err(anyError::new)
.and_then(|_| {
// compile module
@@ -752,7 +753,7 @@ impl<'a> PluginLoader<'a> {
.iter()
.map(ToString::to_string)
.collect();
- let cached_path = ZELLIJ_CACHE_DIR.join(&hash);
+ let cached_path = ZELLIJ_PLUGIN_ARTIFACT_DIR.join(&hash);
self.wasm_blob_on_hd = Some((wasm_bytes.clone(), cached_path.clone()));
Ok((wasm_bytes, cached_path))
},
diff --git a/zellij-utils/src/consts.rs b/zellij-utils/src/consts.rs
index d75934941..0f679f668 100644
--- a/zellij-utils/src/consts.rs
+++ b/zellij-utils/src/consts.rs
@@ -40,6 +40,9 @@ lazy_static! {
ZELLIJ_CACHE_DIR.join("permissions.kdl");
pub static ref ZELLIJ_SESSION_INFO_CACHE_DIR: PathBuf =
ZELLIJ_CACHE_DIR.join(VERSION).join("session_info");
+ pub static ref ZELLIJ_STDIN_CACHE_FILE: PathBuf =
+ ZELLIJ_CACHE_DIR.join(VERSION).join("stdin_cache");
+ pub static ref ZELLIJ_PLUGIN_ARTIFACT_DIR: PathBuf = ZELLIJ_CACHE_DIR.join(VERSION);
}
pub const FEATURES: &[&str] = &[