mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Switch to uzers crate from users
This commit is contained in:
parent
a66eaef0b9
commit
d750909a9d
7 changed files with 54 additions and 69 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
|
@ -2191,22 +2191,22 @@ dependencies = [
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "users"
|
|
||||||
version = "0.11.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "24cc0f6d6f267b73e5a2cadf007ba8f9bc39c6a6f9666f8cf25ea809a153b032"
|
|
||||||
dependencies = [
|
|
||||||
"libc",
|
|
||||||
"log",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "utf8parse"
|
name = "utf8parse"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "uzers"
|
||||||
|
version = "0.11.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76d283dc7e8c901e79e32d077866eaf599156cbf427fffa8289aecc52c5c3f63"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "validator"
|
name = "validator"
|
||||||
version = "0.16.1"
|
version = "0.16.1"
|
||||||
|
|
@ -2736,7 +2736,7 @@ dependencies = [
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
"tracing",
|
"tracing",
|
||||||
"unicode-width",
|
"unicode-width",
|
||||||
"users",
|
"uzers",
|
||||||
"yazi-adaptor",
|
"yazi-adaptor",
|
||||||
"yazi-config",
|
"yazi-config",
|
||||||
"yazi-prebuild",
|
"yazi-prebuild",
|
||||||
|
|
|
||||||
|
|
@ -30,5 +30,5 @@ tokio = { version = "^1", features = [ "parking_lot", "rt-multi-thread"
|
||||||
tokio-util = "^0"
|
tokio-util = "^0"
|
||||||
tracing = { version = "^0", features = [ "max_level_debug", "release_max_level_warn" ] }
|
tracing = { version = "^0", features = [ "max_level_debug", "release_max_level_warn" ] }
|
||||||
unicode-width = "^0"
|
unicode-width = "^0"
|
||||||
|
uzers = "^0"
|
||||||
yazi-prebuild = "0.1.2"
|
yazi-prebuild = "0.1.2"
|
||||||
users = "0.11"
|
|
||||||
0
yazi-plugin/src/os/os.rs
Normal file
0
yazi-plugin/src/os/os.rs
Normal file
|
|
@ -9,8 +9,7 @@ mod preview;
|
||||||
mod target;
|
mod target;
|
||||||
mod text;
|
mod text;
|
||||||
mod time;
|
mod time;
|
||||||
#[cfg(unix)]
|
mod user;
|
||||||
mod unix_user;
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use preview::*;
|
pub use preview::*;
|
||||||
|
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use mlua::{Lua, Table};
|
|
||||||
use users::{Groups, Users, UsersCache};
|
|
||||||
|
|
||||||
use super::Utils;
|
|
||||||
|
|
||||||
impl Utils {
|
|
||||||
pub(super) fn unix_user(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
|
||||||
let arc_cache = Arc::new(UsersCache::new());
|
|
||||||
|
|
||||||
{
|
|
||||||
let cache = Arc::clone(&arc_cache);
|
|
||||||
ya.set("get_current_uid", lua.create_function(move |_, ()| Ok(cache.get_current_uid()))?)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let cache = Arc::clone(&arc_cache);
|
|
||||||
ya.set("get_current_gid", lua.create_function(move |_, ()| Ok(cache.get_current_gid()))?)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let cache = Arc::clone(&arc_cache);
|
|
||||||
ya.set(
|
|
||||||
"get_user_name_by_uid",
|
|
||||||
lua.create_function(move |_, uid: u32| {
|
|
||||||
Ok(
|
|
||||||
cache
|
|
||||||
.get_user_by_uid(uid)
|
|
||||||
.and_then(|u| u.name().to_str().and_then(|n| Some(n.to_owned()))),
|
|
||||||
)
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let cache = Arc::clone(&arc_cache);
|
|
||||||
ya.set(
|
|
||||||
"get_group_name_by_gid",
|
|
||||||
lua.create_function(move |_, gid: u32| {
|
|
||||||
Ok(
|
|
||||||
cache
|
|
||||||
.get_group_by_gid(gid)
|
|
||||||
.and_then(|g| g.name().to_str().and_then(|n| Some(n.to_owned()))),
|
|
||||||
)
|
|
||||||
})?,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
39
yazi-plugin/src/utils/user.rs
Normal file
39
yazi-plugin/src/utils/user.rs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
use mlua::{Lua, Table};
|
||||||
|
use uzers::{Groups, Users, UsersCache};
|
||||||
|
use yazi_shared::RoCell;
|
||||||
|
|
||||||
|
use super::Utils;
|
||||||
|
|
||||||
|
static CACHE: RoCell<UsersCache> = RoCell::new();
|
||||||
|
|
||||||
|
impl Utils {
|
||||||
|
pub(super) fn user(lua: &Lua, ya: &Table) -> mlua::Result<()> {
|
||||||
|
CACHE.with(Default::default);
|
||||||
|
|
||||||
|
ya.set("uid", lua.create_function(|_, ()| Ok(CACHE.get_current_uid()))?)?;
|
||||||
|
|
||||||
|
ya.set("gid", lua.create_function(|_, ()| Ok(CACHE.get_current_gid()))?)?;
|
||||||
|
|
||||||
|
ya.set(
|
||||||
|
"user_name",
|
||||||
|
lua.create_function(|lua, uid: Option<u32>| {
|
||||||
|
CACHE
|
||||||
|
.get_user_by_uid(uid.unwrap_or_else(|| CACHE.get_current_uid()))
|
||||||
|
.map(|s| lua.create_string(s.name().as_encoded_bytes()))
|
||||||
|
.transpose()
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
ya.set(
|
||||||
|
"group_name",
|
||||||
|
lua.create_function(|lua, gid: Option<u32>| {
|
||||||
|
CACHE
|
||||||
|
.get_group_by_gid(gid.unwrap_or_else(|| CACHE.get_current_gid()))
|
||||||
|
.map(|s| lua.create_string(s.name().as_encoded_bytes()))
|
||||||
|
.transpose()
|
||||||
|
})?,
|
||||||
|
)?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,10 +12,9 @@ pub fn install(lua: &Lua) -> mlua::Result<()> {
|
||||||
Utils::plugin(lua, &ya)?;
|
Utils::plugin(lua, &ya)?;
|
||||||
Utils::preview(lua, &ya)?;
|
Utils::preview(lua, &ya)?;
|
||||||
Utils::target(lua, &ya)?;
|
Utils::target(lua, &ya)?;
|
||||||
Utils::time(lua, &ya)?;
|
|
||||||
Utils::text(lua, &ya)?;
|
Utils::text(lua, &ya)?;
|
||||||
#[cfg(unix)]
|
Utils::time(lua, &ya)?;
|
||||||
Utils::unix_user(lua, &ya)?;
|
Utils::user(lua, &ya)?;
|
||||||
|
|
||||||
lua.globals().set("ya", ya)
|
lua.globals().set("ya", ya)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue