diff options
| author | Jonas Maier <> | 2026-03-10 15:00:44 +0100 |
|---|---|---|
| committer | Jonas Maier <> | 2026-03-10 15:00:44 +0100 |
| commit | 83e5044fd6e5c2a8bccd29f5a8462e7016823aed (patch) | |
| tree | 3b07230cc7f373bf49a4d78b61e1635be87bfc93 /src/export_fun.rs | |
| parent | 956e67aafd0ca9bf49782e308644590406d11989 (diff) | |
| download | pish-83e5044fd6e5c2a8bccd29f5a8462e7016823aed.tar.gz | |
defer macro
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(); |
