clean up blob storage on shutdown
The static OnceCell didn't run destructors, so shift to something where we can explicitly trigger them to run and clean up the temporary directory area.
This commit is contained in:
2 files changed
+18
-11
No files matched your search
@@ -1,8 +1,8 @@
|
||||
use crate::{ContentId, Error, LeaseId};
|
||||
use once_cell::sync::OnceCell;
|
||||
use std::io::{BufRead, Seek};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
static STORAGE: OnceCell<Box<dyn BlobStorage + Send + Sync + 'static>> = OnceCell::new();
|
||||
static STORAGE: Mutex<Option<Arc<dyn BlobStorage + Send + Sync + 'static>>> = Mutex::new(None);
|
||||
|
||||
pub trait BufSeekRead: BufRead + Seek {}
|
||||
pub type BoxedReader = Box<dyn BufSeekRead + Send + Sync>;
|
||||
@@ -51,16 +51,21 @@ pub trait BlobStorage {
|
||||
}
|
||||
|
||||
pub fn register_storage(
|
||||
storage: Box<dyn BlobStorage + Send + Sync + 'static>,
|
||||
storage: Arc<dyn BlobStorage + Send + Sync + 'static>,
|
||||
) -> Result<(), Error> {
|
||||
STORAGE
|
||||
.set(storage)
|
||||
.map_err(|_| Error::AlreadyInitializedStorage)
|
||||
STORAGE.lock().unwrap().replace(storage);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn get_storage() -> Result<&'static (dyn BlobStorage + Send + Sync + 'static), Error> {
|
||||
pub fn get_storage() -> Result<Arc<dyn BlobStorage + Send + Sync + 'static>, Error> {
|
||||
STORAGE
|
||||
.get()
|
||||
.map(|s| s.as_ref())
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_ref()
|
||||
.map(|s| s.clone())
|
||||
.ok_or_else(|| Error::StorageNotInit)
|
||||
}
|
||||
|
||||
pub fn clear_storage() {
|
||||
STORAGE.lock().unwrap().take();
|
||||
}
|
||||
@@ -695,7 +695,7 @@ fn run_terminal_gui(opts: StartCommand, default_domain_name: Option<String>) ->
|
||||
if let Some(pos) = opts.position.as_ref() {
|
||||
set_window_position(pos.clone());
|
||||
}
|
||||
wezterm_blob_leases::register_storage(Box::new(
|
||||
wezterm_blob_leases::register_storage(Arc::new(
|
||||
wezterm_blob_leases::simple_tempdir::SimpleTempDir::new()?,
|
||||
))?;
|
||||
|
||||
@@ -1204,7 +1204,9 @@ fn run() -> anyhow::Result<()> {
|
||||
match sub {
|
||||
SubCommand::Start(start) => {
|
||||
log::trace!("Using configuration: {:#?}\nopts: {:#?}", config, opts);
|
||||
run_terminal_gui(start, None)
|
||||
let res = run_terminal_gui(start, None);
|
||||
wezterm_blob_leases::clear_storage();
|
||||
res
|
||||
}
|
||||
SubCommand::Ssh(ssh) => run_ssh(ssh),
|
||||
SubCommand::Serial(serial) => run_serial(config, &serial),
|
||||
|
||||
Reference in new issue
Block a user