diff --git a/yazi-binding/src/cha.rs b/yazi-binding/src/cha.rs index c110322c..8502603f 100644 --- a/yazi-binding/src/cha.rs +++ b/yazi-binding/src/cha.rs @@ -37,16 +37,11 @@ impl Cha { len: t.raw_get("len").unwrap_or_default(), atime: parse_time(t.raw_get("atime").ok())?, btime: parse_time(t.raw_get("btime").ok())?, - #[cfg(unix)] ctime: parse_time(t.raw_get("ctime").ok())?, mtime: parse_time(t.raw_get("mtime").ok())?, - #[cfg(unix)] dev: t.raw_get("dev").unwrap_or_default(), - #[cfg(unix)] uid: t.raw_get("uid").unwrap_or_default(), - #[cfg(unix)] gid: t.raw_get("gid").unwrap_or_default(), - #[cfg(unix)] nlink: t.raw_get("nlink").unwrap_or_default(), }) .into_lua(lua) @@ -70,15 +65,6 @@ impl UserData for Cha { fields.add_field_method_get("is_exec", |_, me| Ok(me.is_exec())); fields.add_field_method_get("is_sticky", |_, me| Ok(me.is_sticky())); - #[cfg(unix)] - { - use std::ops::Not; - fields.add_field_method_get("dev", |_, me| Ok(me.is_dummy().not().then_some(me.dev))); - fields.add_field_method_get("uid", |_, me| Ok(me.is_dummy().not().then_some(me.uid))); - fields.add_field_method_get("gid", |_, me| Ok(me.is_dummy().not().then_some(me.gid))); - fields.add_field_method_get("nlink", |_, me| Ok(me.is_dummy().not().then_some(me.nlink))); - } - fields.add_field_method_get("len", |_, me| Ok(me.len)); fields.add_field_method_get("atime", |_, me| { Ok(me.atime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) @@ -86,13 +72,16 @@ impl UserData for Cha { fields.add_field_method_get("btime", |_, me| { Ok(me.btime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); - #[cfg(unix)] fields.add_field_method_get("ctime", |_, me| { Ok(me.ctime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); fields.add_field_method_get("mtime", |_, me| { Ok(me.mtime.and_then(|t| t.duration_since(UNIX_EPOCH).map(|d| d.as_secs_f64()).ok())) }); + fields.add_field_method_get("dev", |_, me| Ok(me.dev)); + fields.add_field_method_get("uid", |_, me| Ok(me.uid)); + fields.add_field_method_get("gid", |_, me| Ok(me.gid)); + fields.add_field_method_get("nlink", |_, me| Ok(me.nlink)); } fn add_methods>(methods: &mut M) { diff --git a/yazi-fs/src/cha/cha.rs b/yazi-fs/src/cha/cha.rs index 710c41a2..499ce17c 100644 --- a/yazi-fs/src/cha/cha.rs +++ b/yazi-fs/src/cha/cha.rs @@ -13,16 +13,11 @@ pub struct Cha { pub len: u64, pub atime: Option, pub btime: Option, - #[cfg(unix)] pub ctime: Option, pub mtime: Option, - #[cfg(unix)] pub dev: libc::dev_t, - #[cfg(unix)] pub uid: u32, - #[cfg(unix)] pub gid: u32, - #[cfg(unix)] pub nlink: u64, } @@ -35,22 +30,17 @@ impl Deref for Cha { impl Default for Cha { fn default() -> Self { Self { - kind: ChaKind::DUMMY, - mode: ChaMode::empty(), - len: 0, - atime: None, - btime: None, - #[cfg(unix)] - ctime: None, - mtime: None, - #[cfg(unix)] - dev: 0, - #[cfg(unix)] - uid: 0, - #[cfg(unix)] - gid: 0, - #[cfg(unix)] - nlink: 0, + kind: ChaKind::DUMMY, + mode: ChaMode::empty(), + len: 0, + atime: None, + btime: None, + ctime: None, + mtime: None, + dev: 0, + uid: 0, + gid: 0, + nlink: 0, } } } @@ -136,17 +126,15 @@ impl Cha { len: m.len(), atime: m.accessed().ok(), btime: m.created().ok(), - #[cfg(unix)] - ctime: UNIX_EPOCH.checked_add(Duration::new(m.ctime() as u64, m.ctime_nsec() as u32)), + ctime: unix_either!( + UNIX_EPOCH.checked_add(Duration::new(m.ctime() as u64, m.ctime_nsec() as u32)), + None + ), mtime: m.modified().ok(), - #[cfg(unix)] - dev: m.dev() as _, - #[cfg(unix)] - uid: m.uid() as _, - #[cfg(unix)] - gid: m.gid() as _, - #[cfg(unix)] - nlink: m.nlink() as _, + dev: unix_either!(m.dev(), 0) as _, + uid: unix_either!(m.uid(), 0) as _, + gid: unix_either!(m.gid(), 0) as _, + nlink: unix_either!(m.nlink(), 0) as _, } } diff --git a/yazi-plugin/preset/components/linemode.lua b/yazi-plugin/preset/components/linemode.lua index 676569e0..b69944cb 100644 --- a/yazi-plugin/preset/components/linemode.lua +++ b/yazi-plugin/preset/components/linemode.lua @@ -57,9 +57,9 @@ end function Linemode:permissions() return self._file.cha:perm() or "" end function Linemode:owner() - local user = self._file.cha.uid and ya.user_name(self._file.cha.uid) or self._file.cha.uid - local group = self._file.cha.gid and ya.group_name(self._file.cha.gid) or self._file.cha.gid - return string.format("%s:%s", user or "-", group or "-") + local user = ya.user_name and ya.user_name(self._file.cha.uid) or self._file.cha.uid + local group = ya.group_name and ya.group_name(self._file.cha.gid) or self._file.cha.gid + return string.format("%s:%s", user, group) end function Linemode:redraw()