Skip to content

Commit

Permalink
fix: prevent IPC socket cleanup panic
Browse files Browse the repository at this point in the history
Prevent a panic when the IPC socket isn't available when the user quits
`ncspot`.
  • Loading branch information
ThomasFrans authored and hrkfdn committed Oct 14, 2023
1 parent a69e2d7 commit 51d1b34
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ipc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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");
}
}
}

0 comments on commit 51d1b34

Please sign in to comment.