diff --git a/config/src/config.rs b/config/src/config.rs index e51b4d790..aa3b532dc 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -1676,6 +1676,14 @@ fn default_font_size() -> f64 { 12.0 } +pub(crate) fn compute_cache_dir() -> anyhow::Result { + if let Some(runtime) = dirs_next::cache_dir() { + return Ok(runtime.join("wezterm")); + } + + Ok(crate::HOME_DIR.join(".local/share/wezterm")) +} + pub(crate) fn compute_data_dir() -> anyhow::Result { if let Some(runtime) = dirs_next::data_dir() { return Ok(runtime.join("wezterm")); diff --git a/config/src/lib.rs b/config/src/lib.rs index e4928d31c..881cebbcb 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -67,6 +67,7 @@ lazy_static! { pub static ref CONFIG_DIRS: Vec = config_dirs(); pub static ref RUNTIME_DIR: PathBuf = compute_runtime_dir().unwrap(); pub static ref DATA_DIR: PathBuf = compute_data_dir().unwrap(); + pub static ref CACHE_DIR: PathBuf = compute_cache_dir().unwrap(); static ref CONFIG: Configuration = Configuration::new(); static ref CONFIG_FILE_OVERRIDE: Mutex> = Mutex::new(None); static ref CONFIG_SKIP: AtomicBool = AtomicBool::new(false); diff --git a/docs/changelog.md b/docs/changelog.md index 16b1562ed..efe62797a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -81,6 +81,8 @@ As features stabilize some brief notes about them will accumulate here. to @Mrreadiness! #5441 #5304 * Search mode now accepts composed input from the IME. Thanks to @kenchou! #5564 * Quick select mode will now accept unix paths with `//` in them. #5763 +* blob leases (for image rendering) could be removed by temporary directory + cleaners, resulting in issues with rendering. #5422 #### Updated * Bundled conpty.dll and OpenConsole.exe to build 1.19.240130002.nupkg diff --git a/wezterm-blob-leases/src/simple_tempdir.rs b/wezterm-blob-leases/src/simple_tempdir.rs index 1f504ccf9..0137cbc04 100644 --- a/wezterm-blob-leases/src/simple_tempdir.rs +++ b/wezterm-blob-leases/src/simple_tempdir.rs @@ -4,7 +4,7 @@ use crate::{BlobStorage, BoxedReader, BufSeekRead, ContentId, Error, LeaseId}; use std::collections::HashMap; use std::fs::File; use std::io::{BufReader, Write}; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::Mutex; use tempfile::TempDir; @@ -25,6 +25,19 @@ impl SimpleTempDir { }) } + pub fn new_in>(path: P) -> Result { + let path = path.as_ref(); + std::fs::create_dir_all(path)?; + let root = tempfile::Builder::new() + .prefix("wezterm-blob-lease-") + .rand_bytes(8) + .tempdir_in(path)?; + Ok(Self { + root, + refs: Mutex::new(HashMap::new()), + }) + } + fn path_for_content(&self, content_id: ContentId) -> Result { let path = self.root.path().join(format!("{content_id}")); std::fs::create_dir_all(path.parent().unwrap())?; diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index f3b7688ac..4d2829aa4 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -414,9 +414,8 @@ async fn async_run_terminal_gui( config::RUNTIME_DIR.join(format!("gui-sock-{}", unsafe { libc::getpid() })); std::env::set_var("WEZTERM_UNIX_SOCKET", unix_socket_path.clone()); wezterm_blob_leases::register_storage(Arc::new( - wezterm_blob_leases::simple_tempdir::SimpleTempDir::new()?, + wezterm_blob_leases::simple_tempdir::SimpleTempDir::new_in(&*config::CACHE_DIR)?, ))?; - if let Err(err) = spawn_mux_server(unix_socket_path, should_publish) { log::warn!("{:#}", err); } diff --git a/wezterm-mux-server/src/main.rs b/wezterm-mux-server/src/main.rs index b92c03ae5..09f5aee07 100644 --- a/wezterm-mux-server/src/main.rs +++ b/wezterm-mux-server/src/main.rs @@ -205,7 +205,7 @@ fn run() -> anyhow::Result<()> { } wezterm_blob_leases::register_storage(Arc::new( - wezterm_blob_leases::simple_tempdir::SimpleTempDir::new()?, + wezterm_blob_leases::simple_tempdir::SimpleTempDir::new_in(&*config::CACHE_DIR)?, ))?; let need_builder = !opts.prog.is_empty() || opts.cwd.is_some();