diff options
Diffstat (limited to 'src/export_fun.rs')
| -rw-r--r-- | src/export_fun.rs | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/export_fun.rs b/src/export_fun.rs index ecbdf46..a98699c 100644 --- a/src/export_fun.rs +++ b/src/export_fun.rs @@ -5,6 +5,7 @@ use nix::poll::PollFlags; use nix::poll::poll; use crate::Session; +use crate::defer; use crate::run::Input; use crate::run::Output; use crate::run::get_command_kind; @@ -32,7 +33,6 @@ use std::sync::Arc; use std::sync::Mutex; use std::sync::mpsc; use std::sync::mpsc::Receiver; -use std::sync::mpsc::Sender; use std::thread; use std::time::Duration; @@ -204,7 +204,9 @@ impl Drop for SocketDropper { // wait 1s for background to exit if let Err(e) = sr.recv.recv_timeout(Duration::from_secs(1)) { - eprintln!("background thread is still running({e:?}, session might not be cleaned up\r"); + eprintln!( + "background thread is still running({e:?}, session might not be cleaned up\r" + ); } } } @@ -231,19 +233,9 @@ pub fn listen(session: Arc<Mutex<Session>>) -> impl Drop { let se = session.clone(); thread::spawn(move || { - struct SessionRemover { - send: Sender<()>, - path: PathBuf, - } - impl Drop for SessionRemover { - fn drop(&mut self) { - let _ = fs::remove_dir_all(&self.path); - let _ = self.send.send(()); - } - } - let _session_remover = SessionRemover { - path: session_dir, - send, + defer! { + let _ = fs::remove_dir_all(session_dir); + let _ = send.send(()); }; let listener = UnixListener::bind(socket_path).unwrap(); |
