From bcfe922babb1faec495a7ce219c9f7864131b482 Mon Sep 17 00:00:00 2001 From: Jonathan Teran Date: Wed, 21 Sep 2022 14:49:02 -0300 Subject: [PATCH] fix: unix sockets detection (#31) * correctly detect unix sockets * Update src/mpd_conn.rs Co-authored-by: Jake Stanger * style: run cargo fmt Co-authored-by: Jake Stanger --- src/mpd_conn.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mpd_conn.rs b/src/mpd_conn.rs index 38c6b91..6070001 100644 --- a/src/mpd_conn.rs +++ b/src/mpd_conn.rs @@ -6,6 +6,7 @@ use discord_rpc_client::models::ActivityTimestamps; use mpd_client::commands::responses::{PlayState, Song, Status}; use mpd_client::raw::MpdProtocolError; use mpd_client::{commands, Client as MPDClient, Connection, Tag}; +use std::os::unix::fs::FileTypeExt; /// Cycles through each MPD host and /// returns the first one which is playing, @@ -34,7 +35,12 @@ pub(crate) async fn try_get_mpd_conn(hosts: &[String]) -> Option { } fn is_unix_socket(host: &String) -> bool { - PathBuf::from(host).is_file() + let path = PathBuf::from(host); + path.exists() + && match path.metadata() { + Ok(metadata) => metadata.file_type().is_socket(), + Err(_) => false, + } } async fn connect_unix(host: &String) -> Result {