Skip to content

Commit

Permalink
fix(mpd): incorrectly checking for unix sockets
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeStanger committed Oct 14, 2022
1 parent 006c242 commit 8536ad7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/modules/mpd/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use mpd_client::responses::Status;
use mpd_client::Client;
use std::collections::HashMap;
use std::fmt::{Display, Formatter};
use std::os::unix::fs::FileTypeExt;
use std::path::PathBuf;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -137,7 +138,12 @@ async fn try_get_mpd_conn(host: &str) -> Result<Connection, MpdProtocolError> {
}

fn is_unix_socket(host: &str) -> 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: &str) -> Result<Connection, MpdProtocolError> {
Expand Down

0 comments on commit 8536ad7

Please sign in to comment.