fix: blob leases could be broken by tmpwatch

Let's put them in an application-specific cache directory
location instead.

refs: #5422
This commit is contained in:
Wez Furlong committed 2024-07-14 07:10:17 -07:00
1 parent 4884f31762
commit ff4528e783
6 files changed
+27 -4

No files matched your search

+8
View File
@@ -1676,6 +1676,14 @@ fn default_font_size() -> f64 {
12.0
}
pub(crate) fn compute_cache_dir() -> anyhow::Result<PathBuf> {
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<PathBuf> {
if let Some(runtime) = dirs_next::data_dir() {
return Ok(runtime.join("wezterm"));
+1
View File
@@ -67,6 +67,7 @@ lazy_static! {
pub static ref CONFIG_DIRS: Vec<PathBuf> = 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<Option<PathBuf>> = Mutex::new(None);
static ref CONFIG_SKIP: AtomicBool = AtomicBool::new(false);
+2
View File
@@ -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
+14 -1
View File
@@ -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<P: AsRef<Path>>(path: P) -> Result<Self, Error> {
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<PathBuf, Error> {
let path = self.root.path().join(format!("{content_id}"));
std::fs::create_dir_all(path.parent().unwrap())?;
+1 -2
View File
@@ -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);
}
+1 -1
View File
@@ -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();