Skip to content

Commit

Permalink
fix: use a different cache directory for each user to avoid permissio…
Browse files Browse the repository at this point in the history
…n issues (#1541)
  • Loading branch information
sxyazi authored Aug 23, 2024
1 parent 4fa37cb commit 91da9d1
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion yazi-dds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
6 changes: 0 additions & 6 deletions yazi-dds/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ use server::*;
pub use state::*;
use stream::*;

#[cfg(unix)]
pub static USERS_CACHE: yazi_shared::RoCell<uzers::UsersCache> = yazi_shared::RoCell::new();

pub fn init() {
let (tx, rx) = tokio::sync::mpsc::unbounded_channel();

Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions yazi-dds/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
2 changes: 1 addition & 1 deletion yazi-plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 1 addition & 2 deletions yazi-plugin/src/utils/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
3 changes: 3 additions & 0 deletions yazi-shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }

Expand Down
7 changes: 6 additions & 1 deletion yazi-shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
3 changes: 3 additions & 0 deletions yazi-shared/src/os.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(unix)]
pub static USERS_CACHE: crate::RoCell<uzers::UsersCache> = crate::RoCell::new();

#[cfg(unix)]
pub fn hostname() -> Result<String, std::io::Error> {
use std::io::{Error, ErrorKind};
Expand Down
13 changes: 12 additions & 1 deletion yazi-shared/src/xdg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 91da9d1

Please sign in to comment.