Skip to content

Commit

Permalink
minor paths refactoring
Browse files Browse the repository at this point in the history
- move stdin cache to existing path with version
- define consts
  • Loading branch information
tlinford committed Oct 4, 2023
1 parent 1564dab commit 6e37c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
17 changes: 7 additions & 10 deletions zellij-client/src/stdin_ansi_parser.rs
Original file line number Diff line number Diff line change
@@ -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_DIR, 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)]
Expand Down Expand Up @@ -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_DIR.as_path())
{
Ok(mut file) => {
let mut json_cache = String::new();
file.read_to_string(&mut json_cache).ok()?;
Expand All @@ -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_DIR.as_path()) {
let _ = file.write_all(serialized_events.as_bytes());
}
};
Expand Down Expand Up @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions zellij-server/src/plugins/plugin_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
use url::Url;
use wasmer::{AsStoreRef, Instance, Module, Store};
use wasmer_wasi::{Pipe, WasiState};
use zellij_utils::consts::VERSION;
use zellij_utils::consts::ZELLIJ_PLUGIN_ARTIFACT_DIR;
use zellij_utils::prost::Message;

use crate::{
Expand Down Expand Up @@ -753,7 +753,7 @@ impl<'a> PluginLoader<'a> {
.iter()
.map(ToString::to_string)
.collect();
let cached_path = ZELLIJ_CACHE_DIR.join(VERSION).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))
},
Expand Down

0 comments on commit 6e37c65

Please sign in to comment.