diff options
| author | Irene Knapp <ireneista@irenes.space> | 2026-11-23 23:13:40 -0700 |
|---|---|---|
| committer | Irene Knapp <ireneista@irenes.space> | 2026-11-23 23:13:40 -0700 |
| commit | 61120e03d030f14126163aa02fd78989e83aa394 (patch) | |
| tree | d6d2481fe3782ea5ee68bfdba82bc164e241ae91 | |
| parent | a75729a759108ae672d8d1cfcc6252a6b680ef1f (diff) | |
more progress on finding the i3 socket
Force-Push: yes Change-Id: Iacdfbe0b824b0ebe8d53943cb1b480985f787af2
| -rw-r--r-- | src/facility/i3.rs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/facility/i3.rs b/src/facility/i3.rs index 7ee29dc..2911b4b 100644 --- a/src/facility/i3.rs +++ b/src/facility/i3.rs @@ -5,7 +5,9 @@ use crate::xdg::xdg_runtime_directory; use std::any::Any; use std::path::{ Path, PathBuf }; -use async_fs::File; +use async_fs::{ metadata, read_dir, File }; +use async_fs::unix::FileTypeExt; +use futures_lite::StreamExt; pub struct I3 { @@ -83,12 +85,42 @@ impl I3 { } async fn try_socket_directory(path: &Path) -> Result<Option<File>> { + let mut directory = read_dir(path).await?; + + while let Some(entry) = directory.try_next().await? { + /* Do not follow symlinks for the name check. + * + * Note also that if the name isn't valid Unicode, it doesn't match the + * pattern anyway. + */ + if let Some(name) = entry.file_name().to_str() { + let prefix = "ipc-socket."; + if name.starts_with(prefix) { + let tail = &name[prefix.len() ..]; + + if tail.len() > 0 + && tail.chars().all(|c| { c.is_ascii_digit() }) + { + let full_path = path.join(name); + if let Some(socket) = Self::try_socket_path(&full_path).await? { + return Ok(Some(socket)); + } + } + } + } + } + Ok(None) } async fn try_socket_path(path: &Path) -> Result<Option<File>> { - Ok(None) - } + /* Do follow symlinks, for the socket check. */ + if !metadata(path).await?.file_type().is_socket() { + return Ok(None); + } + let socket = File::open(path).await?; + Ok(Some(socket)) + } } |