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
This commit is contained in:
Thomas Linford 2023-10-12 09:55:27 +02:00 committed by GitHub
parent efca21a6ed
commit fb1af39aca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 12 deletions

View File

@ -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)]

View File

@ -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))
},

View File

@ -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] = &[