From e7d2ec246055d5dbe8ae3ad324111adc7ce361ee Mon Sep 17 00:00:00 2001 From: AidanV Date: Sun, 21 Apr 2024 17:32:53 -0700 Subject: [PATCH] switched to using ya.user_name --- Cargo.lock | 11 ----------- yazi-plugin/preset/components/folder.lua | 6 +++++- yazi-plugin/src/bindings/cha.rs | 8 -------- yazi-shared/Cargo.toml | 1 - yazi-shared/src/fs/fns.rs | 13 ------------- 5 files changed, 5 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0542db4a..94e6cbbf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2272,16 +2272,6 @@ dependencies = [ "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]] name = "utf8parse" version = "0.2.1" @@ -2931,7 +2921,6 @@ dependencies = [ "serde", "tokio", "tracing", - "users", ] [[package]] diff --git a/yazi-plugin/preset/components/folder.lua b/yazi-plugin/preset/components/folder.lua index 2ddd7197..ac774603 100644 --- a/yazi-plugin/preset/components/folder.lua +++ b/yazi-plugin/preset/components/folder.lua @@ -22,7 +22,11 @@ function Folder:linemode(area, files) elseif mode == "permissions" then spans[#spans + 1] = ui.Span(f.cha:permissions() or "") elseif mode == "owner" then - spans[#spans + 1] = ui.Span(f.cha:owner() or "") + local username = ya.user_name(f.cha.uid) + local groupname = ya.group_name(f.cha.gid) + if username and groupname then + spans[#spans + 1] = ui.Span(username .. ":" .. groupname) + end end spans[#spans + 1] = ui.Span(" ") diff --git a/yazi-plugin/src/bindings/cha.rs b/yazi-plugin/src/bindings/cha.rs index 324f22c4..68b81c05 100644 --- a/yazi-plugin/src/bindings/cha.rs +++ b/yazi-plugin/src/bindings/cha.rs @@ -44,14 +44,6 @@ impl Cha { None::, ) }); - reg.add_method("owner", |_, me, ()| { - Ok( - #[cfg(unix)] - Some(yazi_shared::fs::owner(me.uid, me.gid)), - #[cfg(windows)] - None::, - ) - }); })?; Ok(()) diff --git a/yazi-shared/Cargo.toml b/yazi-shared/Cargo.toml index e03664c0..f1fdf534 100644 --- a/yazi-shared/Cargo.toml +++ b/yazi-shared/Cargo.toml @@ -27,4 +27,3 @@ tracing = { version = "0.1.40", features = [ "max_level_debug", "release_max_lev [target."cfg(unix)".dependencies] libc = "0.2.153" -users = "0.11.0" diff --git a/yazi-shared/src/fs/fns.rs b/yazi-shared/src/fs/fns.rs index b7b0f14b..97934573 100644 --- a/yazi-shared/src/fs/fns.rs +++ b/yazi-shared/src/fs/fns.rs @@ -147,19 +147,6 @@ pub fn permissions(m: libc::mode_t) -> String { s } -#[cfg(unix)] -pub fn owner(uid: u32, gid: u32) -> String { - let username = match users::get_user_by_uid(uid) { - Some(u) => u.name().to_str().unwrap_or_default().to_string(), - None => String::default(), - }; - let groupname = match users::get_group_by_gid(gid) { - Some(g) => g.name().to_str().unwrap_or_default().to_string(), - None => String::default(), - }; - format!("{username} {groupname}") -} - // Find the max common root in a list of files // e.g. /a/b/c, /a/b/d -> /a/b // /aa/bb/cc, /aa/dd/ee -> /aa