chore: more robust xdg path handling

This commit is contained in:
atagen 2025-06-22 23:51:54 +10:00
parent 1318c51a44
commit 66d1dfacda
2 changed files with 20 additions and 4 deletions

View file

@ -2,10 +2,13 @@ use std::{
collections::{BTreeMap, HashMap},
net::SocketAddr,
os::linux::net::SocketAddrExt,
path::PathBuf,
str::FromStr,
};
use crate::socket::{create_niri_socket, tell};
use anyhow::{Error, Result, anyhow};
use microxdg::Xdg;
use niri_ipc::{Event, Request};
use niri_tag::{TagCmd, TagEvent, TagState};
use nix::unistd::geteuid;
@ -35,8 +38,16 @@ pub async fn event_consumer(tx: channel::Sender<Event>) -> Result<()> {
unreachable!("Listener loop ended");
}
fn get_run_path() -> Result<PathBuf> {
let xdg = Xdg::new()?;
Ok(xdg
.runtime()?
.unwrap_or(PathBuf::from_str(&format!("/run/user/{}", geteuid()))?))
}
async fn create_provider_socket(name: &'static str, socket: &'static str) -> Result<UnixListener> {
let sock_path = format!("/run/user/{}/{}.sock", geteuid(), socket);
let mut sock_path = get_run_path()?;
sock_path.push(format!("{}.sock", socket));
if smol::fs::metadata(&sock_path).await.is_ok() {
tracing::debug!("removing old {} socket", name);
smol::fs::remove_file(&sock_path).await?;