fix: prevent IPC socket cleanup panic
Prevent a panic when the IPC socket isn't available when the user quits `ncspot`.
This commit is contained in:
committed by
Henrik Friedrichsen
parent
a69e2d763b
commit
51d1b34ccc
13
src/ipc.rs
13
src/ipc.rs
@@ -26,8 +26,7 @@ struct Status {
|
||||
|
||||
impl Drop for IpcSocket {
|
||||
fn drop(&mut self) {
|
||||
log::info!("Removing IPC socket: {:?}", self.path);
|
||||
std::fs::remove_file(&self.path).expect("Could not remove IPC socket");
|
||||
self.try_remove_socket();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,4 +125,14 @@ impl IpcSocket {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Try to remove the IPC socket if there is one for this instance of `ncspot`. Don't do
|
||||
/// anything if the socket has already been removed for some reason.
|
||||
fn try_remove_socket(&mut self) {
|
||||
if std::fs::remove_file(&self.path).is_ok() {
|
||||
info!("removed socket at {:?}", self.path);
|
||||
} else {
|
||||
info!("socket already removed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user