diff --git a/Cargo.lock b/Cargo.lock index edeb9f24..b376e14e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3071,6 +3071,7 @@ dependencies = [ "clap_complete_fig", "clap_complete_nushell", "serde", + "uzers", "vergen", "yazi-adaptor", "yazi-config", @@ -3139,6 +3140,7 @@ dependencies = [ "serde_json", "tokio", "tracing", + "uzers", "yazi-boot", "yazi-shared", ] diff --git a/yazi-boot/Cargo.toml b/yazi-boot/Cargo.toml index 7cd107d2..3e0734fd 100644 --- a/yazi-boot/Cargo.toml +++ b/yazi-boot/Cargo.toml @@ -23,3 +23,6 @@ clap_complete = "4.5.1" clap_complete_nushell = "4.5.1" clap_complete_fig = "4.5.0" vergen = { version = "8.3.1", features = [ "build", "git", "gitcl" ] } + +[target."cfg(unix)".dependencies] +uzers = "0.11.3" diff --git a/yazi-boot/src/lib.rs b/yazi-boot/src/lib.rs index 569424dc..11986a77 100644 --- a/yazi-boot/src/lib.rs +++ b/yazi-boot/src/lib.rs @@ -9,7 +9,13 @@ pub use boot::*; pub static ARGS: RoCell = RoCell::new(); pub static BOOT: RoCell = RoCell::new(); +#[cfg(unix)] +pub static USERS_CACHE: yazi_shared::RoCell = yazi_shared::RoCell::new(); + pub fn init() { ARGS.with(Default::default); BOOT.with(Default::default); + + #[cfg(unix)] + USERS_CACHE.with(Default::default); } diff --git a/yazi-dds/Cargo.toml b/yazi-dds/Cargo.toml index e05bedd9..5568125d 100644 --- a/yazi-dds/Cargo.toml +++ b/yazi-dds/Cargo.toml @@ -22,3 +22,6 @@ tokio = { version = "1.37.0", features = [ "full" ] } # Logging tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] } + +[target."cfg(unix)".dependencies] +uzers = "0.11.3" diff --git a/yazi-dds/src/body/body.rs b/yazi-dds/src/body/body.rs index d4639c10..693d987b 100644 --- a/yazi-dds/src/body/body.rs +++ b/yazi-dds/src/body/body.rs @@ -37,6 +37,9 @@ impl<'a> Body<'a> { "hi" | "hey" | "cd" | "hover" | "rename" | "bulk" | "yank" => { Err("Cannot construct system event from Lua").into_lua_err()? } + _ if !kind.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-') => { + Err("Kind must be alphanumeric with dashes").into_lua_err()? + } _ => BodyCustom::from_lua(kind, value)?, }) } diff --git a/yazi-dds/src/client.rs b/yazi-dds/src/client.rs index 5cf5c4d6..e2e4b7e7 100644 --- a/yazi-dds/src/client.rs +++ b/yazi-dds/src/client.rs @@ -75,7 +75,7 @@ impl Client { ) -> (Lines>>, WriteHalf) { let mut first = true; loop { - if let Ok(stream) = UnixStream::connect("/tmp/yazi.sock").await { + if let Ok(stream) = UnixStream::connect(Server::socket_file()).await { Pubsub::pub_from_hi(); let (reader, writer) = tokio::io::split(stream); return (BufReader::new(reader).lines(), writer); diff --git a/yazi-dds/src/server.rs b/yazi-dds/src/server.rs index ae52161b..dfd3d102 100644 --- a/yazi-dds/src/server.rs +++ b/yazi-dds/src/server.rs @@ -61,7 +61,7 @@ impl Server { continue; } - if receiver == 0 && sender > 0 && sender <= u16::MAX as u64 { + if receiver == 0 && sender <= u16::MAX as u64 { let Some(body) = parts.next() else { continue }; if !STATE.set(kind, sender as u16, body) { continue } } @@ -78,11 +78,23 @@ impl Server { })) } + #[cfg(unix)] + #[inline] + pub(super) fn socket_file() -> std::path::PathBuf { + use uzers::Users; + use yazi_boot::USERS_CACHE; + use yazi_shared::Xdg; + + Xdg::cache_dir().join(format!(".dds-{}.sock", USERS_CACHE.get_current_uid())) + } + #[cfg(unix)] #[inline] async fn bind() -> Result { - tokio::fs::remove_file("/tmp/yazi.sock").await.ok(); - Ok(tokio::net::UnixListener::bind("/tmp/yazi.sock")?) + let p = Self::socket_file(); + + tokio::fs::remove_file(&p).await.ok(); + Ok(tokio::net::UnixListener::bind(p)?) } #[cfg(not(unix))] diff --git a/yazi-plugin/src/bindings/cha.rs b/yazi-plugin/src/bindings/cha.rs index 99ad8701..68b81c05 100644 --- a/yazi-plugin/src/bindings/cha.rs +++ b/yazi-plugin/src/bindings/cha.rs @@ -17,6 +17,8 @@ impl Cha { reg.add_field_method_get("is_char_device", |_, me| Ok(me.is_char_device())); reg.add_field_method_get("is_fifo", |_, me| Ok(me.is_fifo())); reg.add_field_method_get("is_socket", |_, me| Ok(me.is_socket())); + reg.add_field_method_get("is_exec", |_, me| Ok(me.is_exec())); + reg.add_field_method_get("is_sticky", |_, me| Ok(me.is_sticky())); #[cfg(unix)] { diff --git a/yazi-plugin/src/lua.rs b/yazi-plugin/src/lua.rs index 0715d198..a320c7bd 100644 --- a/yazi-plugin/src/lua.rs +++ b/yazi-plugin/src/lua.rs @@ -16,7 +16,6 @@ pub(super) fn init_lua() { fn stage_1(lua: &'static Lua) -> Result<()> { crate::Config::new(lua).install_boot()?.install_manager()?.install_theme()?; - crate::utils::init(); crate::utils::install(lua)?; // Base diff --git a/yazi-plugin/src/pubsub/pubsub.rs b/yazi-plugin/src/pubsub/pubsub.rs index 0f479154..08aaf7bf 100644 --- a/yazi-plugin/src/pubsub/pubsub.rs +++ b/yazi-plugin/src/pubsub/pubsub.rs @@ -28,10 +28,6 @@ impl Pubsub { ps.raw_set( "pub_static", lua.create_function(|_, (severity, kind, value): (u16, mlua::String, Value)| { - if severity < 1 { - return Err("Severity must be at least 1").into_lua_err(); - } - yazi_dds::Pubsub::pub_static( severity, Body::from_lua(kind.to_str()?, value).into_lua_err()?, diff --git a/yazi-plugin/src/utils/user.rs b/yazi-plugin/src/utils/user.rs index 473fb3ac..ac102335 100644 --- a/yazi-plugin/src/utils/user.rs +++ b/yazi-plugin/src/utils/user.rs @@ -6,9 +6,10 @@ impl Utils { #[cfg(unix)] pub(super) fn user(lua: &Lua, ya: &Table) -> mlua::Result<()> { use uzers::{Groups, Users}; + use yazi_boot::USERS_CACHE; use yazi_shared::hostname; - use crate::utils::{HOSTNAME_CACHE, USERS_CACHE}; + use crate::utils::HOSTNAME_CACHE; ya.raw_set("uid", lua.create_function(|_, ()| Ok(USERS_CACHE.get_current_uid()))?)?; diff --git a/yazi-plugin/src/utils/utils.rs b/yazi-plugin/src/utils/utils.rs index 6183f0b8..929284c8 100644 --- a/yazi-plugin/src/utils/utils.rs +++ b/yazi-plugin/src/utils/utils.rs @@ -1,6 +1,3 @@ -#[cfg(unix)] -pub(super) static USERS_CACHE: yazi_shared::RoCell = yazi_shared::RoCell::new(); - #[cfg(unix)] pub(super) static HOSTNAME_CACHE: std::sync::OnceLock> = std::sync::OnceLock::new(); @@ -43,8 +40,3 @@ pub fn install_isolate(lua: &mlua::Lua) -> mlua::Result<()> { lua.globals().raw_set("ya", ya) } - -pub fn init() { - #[cfg(unix)] - USERS_CACHE.with(Default::default); -}