Skip to content

Commit

Permalink
fix: unix sockets detection (#31)
Browse files Browse the repository at this point in the history
* correctly detect unix sockets

* Update src/mpd_conn.rs

Co-authored-by: Jake Stanger <[email protected]>

* style: run cargo fmt

Co-authored-by: Jake Stanger <[email protected]>
  • Loading branch information
jonathannerat and JakeStanger authored Sep 21, 2022
1 parent 6ba7cd9 commit bcfe922
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mpd_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -34,7 +35,12 @@ pub(crate) async fn try_get_mpd_conn(hosts: &[String]) -> Option<MPDClient> {
}

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<Connection, MpdProtocolError> {
Expand Down

0 comments on commit bcfe922

Please sign in to comment.