fix: use a different cache directory for each user to avoid permission issues (#1541)

This commit is contained in:
三咲雅 · Misaki Masa 2024-08-23 18:28:47 +08:00 committed by GitHub
parent 4fa37cb3cd
commit 91da9d19cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 30 additions and 14 deletions

1
Cargo.lock generated
View file

@ -3477,6 +3477,7 @@ dependencies = [
"serde",
"shell-words",
"tokio",
"uzers",
"windows-sys 0.59.0",
]

View file

@ -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"

View file

@ -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 }

View file

@ -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();
@ -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);

View file

@ -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()))
}

View file

@ -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"

View file

@ -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;

View file

@ -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" ] }

View file

@ -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();
}

View file

@ -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};

View file

@ -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)
}
}