diff --git a/Cargo.lock b/Cargo.lock index de50e36b..bdeac22f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3477,6 +3477,7 @@ dependencies = [ "serde", "shell-words", "tokio", + "uzers", "windows-sys 0.59.0", ] diff --git a/Cargo.toml b/Cargo.toml index 3648a468..7ffee044 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,3 +35,4 @@ tokio-stream = "0.1.15" tokio-util = "0.7.11" tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_level_warn" ] } unicode-width = "0.1.13" +uzers = "0.12.1" diff --git a/yazi-dds/Cargo.toml b/yazi-dds/Cargo.toml index 3ace5361..e736319d 100644 --- a/yazi-dds/Cargo.toml +++ b/yazi-dds/Cargo.toml @@ -31,4 +31,4 @@ tracing = { workspace = true } vergen-gitcl = { version = "1.0.0", features = [ "build" ] } [target."cfg(unix)".dependencies] -uzers = "0.12.1" +uzers = { workspace = true } diff --git a/yazi-dds/src/lib.rs b/yazi-dds/src/lib.rs index 66e45493..df2bc66b 100644 --- a/yazi-dds/src/lib.rs +++ b/yazi-dds/src/lib.rs @@ -18,9 +18,6 @@ use server::*; pub use state::*; use stream::*; -#[cfg(unix)] -pub static USERS_CACHE: yazi_shared::RoCell = yazi_shared::RoCell::new(); - pub fn init() { let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); @@ -38,9 +35,6 @@ pub fn init() { LOCAL.with(<_>::default); REMOTE.with(<_>::default); - #[cfg(unix)] - USERS_CACHE.with(<_>::default); - // Env if let Some(s) = std::env::var("YAZI_ID").ok().filter(|s| !s.is_empty()) { std::env::set_var("YAZI_PID", s); diff --git a/yazi-dds/src/stream.rs b/yazi-dds/src/stream.rs index 2262c66c..15c1176f 100644 --- a/yazi-dds/src/stream.rs +++ b/yazi-dds/src/stream.rs @@ -52,8 +52,7 @@ impl Stream { use std::env::temp_dir; use uzers::Users; - - use crate::USERS_CACHE; + use yazi_shared::USERS_CACHE; temp_dir().join(format!(".yazi_dds-{}.sock", USERS_CACHE.get_current_uid())) } diff --git a/yazi-plugin/Cargo.toml b/yazi-plugin/Cargo.toml index 8ece9276..c6e69883 100644 --- a/yazi-plugin/Cargo.toml +++ b/yazi-plugin/Cargo.toml @@ -41,7 +41,7 @@ unicode-width = { workspace = true } yazi-prebuild = "0.1.2" [target."cfg(unix)".dependencies] -uzers = "0.12.1" +uzers = { workspace = true } [target."cfg(windows)".dependencies] clipboard-win = "5.4.0" diff --git a/yazi-plugin/src/utils/user.rs b/yazi-plugin/src/utils/user.rs index 0679e405..c7449faf 100644 --- a/yazi-plugin/src/utils/user.rs +++ b/yazi-plugin/src/utils/user.rs @@ -6,8 +6,7 @@ impl Utils { #[cfg(unix)] pub(super) fn user(lua: &Lua, ya: &Table) -> mlua::Result<()> { use uzers::{Groups, Users}; - use yazi_dds::USERS_CACHE; - use yazi_shared::hostname; + use yazi_shared::{hostname, USERS_CACHE}; use crate::utils::HOSTNAME_CACHE; diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index 1976613b..079dded1 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -24,6 +24,9 @@ serde = { workspace = true } shell-words = { workspace = true } tokio = { workspace = true } +[target."cfg(unix)".dependencies] +uzers = { workspace = true } + [target.'cfg(windows)'.dependencies] windows-sys = { version = "0.59.0", features = [ "Win32_Storage_FileSystem", "Win32_UI_Shell" ] } diff --git a/yazi-shared/src/lib.rs b/yazi-shared/src/lib.rs index fbbf0230..45eeed8b 100644 --- a/yazi-shared/src/lib.rs +++ b/yazi-shared/src/lib.rs @@ -39,4 +39,9 @@ pub use time::*; pub use translit::*; pub use xdg::*; -pub fn init() { event::Event::init(); } +pub fn init() { + #[cfg(unix)] + USERS_CACHE.with(<_>::default); + + event::Event::init(); +} diff --git a/yazi-shared/src/os.rs b/yazi-shared/src/os.rs index 9bcc1d2d..56bdc4c7 100644 --- a/yazi-shared/src/os.rs +++ b/yazi-shared/src/os.rs @@ -1,3 +1,6 @@ +#[cfg(unix)] +pub static USERS_CACHE: crate::RoCell = crate::RoCell::new(); + #[cfg(unix)] pub fn hostname() -> Result { use std::io::{Error, ErrorKind}; diff --git a/yazi-shared/src/xdg.rs b/yazi-shared/src/xdg.rs index 820b2e19..f8e13c8f 100644 --- a/yazi-shared/src/xdg.rs +++ b/yazi-shared/src/xdg.rs @@ -44,5 +44,16 @@ impl Xdg { } #[inline] - pub fn cache_dir() -> PathBuf { env::temp_dir().join("yazi") } + pub fn cache_dir() -> PathBuf { + #[cfg(unix)] + let s = { + use uzers::Users; + format!("yazi-{}", crate::USERS_CACHE.get_current_uid()) + }; + + #[cfg(windows)] + let s = "yazi"; + + env::temp_dir().join(s) + } }