This commit is contained in:
sxyazi 2025-09-17 08:23:04 +08:00
parent c9e929fdc3
commit f734147120
No known key found for this signature in database
3 changed files with 26 additions and 49 deletions

View file

@ -37,16 +37,11 @@ impl Cha {
len: t.raw_get("len").unwrap_or_default(), len: t.raw_get("len").unwrap_or_default(),
atime: parse_time(t.raw_get("atime").ok())?, atime: parse_time(t.raw_get("atime").ok())?,
btime: parse_time(t.raw_get("btime").ok())?, btime: parse_time(t.raw_get("btime").ok())?,
#[cfg(unix)]
ctime: parse_time(t.raw_get("ctime").ok())?, ctime: parse_time(t.raw_get("ctime").ok())?,
mtime: parse_time(t.raw_get("mtime").ok())?, mtime: parse_time(t.raw_get("mtime").ok())?,
#[cfg(unix)]
dev: t.raw_get("dev").unwrap_or_default(), dev: t.raw_get("dev").unwrap_or_default(),
#[cfg(unix)]
uid: t.raw_get("uid").unwrap_or_default(), uid: t.raw_get("uid").unwrap_or_default(),
#[cfg(unix)]
gid: t.raw_get("gid").unwrap_or_default(), gid: t.raw_get("gid").unwrap_or_default(),
#[cfg(unix)]
nlink: t.raw_get("nlink").unwrap_or_default(), nlink: t.raw_get("nlink").unwrap_or_default(),
}) })
.into_lua(lua) .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_exec", |_, me| Ok(me.is_exec()));
fields.add_field_method_get("is_sticky", |_, me| Ok(me.is_sticky())); 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("len", |_, me| Ok(me.len));
fields.add_field_method_get("atime", |_, me| { 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())) 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| { 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())) 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| { 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())) 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| { 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())) 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<M: UserDataMethods<Self>>(methods: &mut M) { fn add_methods<M: UserDataMethods<Self>>(methods: &mut M) {

View file

@ -13,16 +13,11 @@ pub struct Cha {
pub len: u64, pub len: u64,
pub atime: Option<SystemTime>, pub atime: Option<SystemTime>,
pub btime: Option<SystemTime>, pub btime: Option<SystemTime>,
#[cfg(unix)]
pub ctime: Option<SystemTime>, pub ctime: Option<SystemTime>,
pub mtime: Option<SystemTime>, pub mtime: Option<SystemTime>,
#[cfg(unix)]
pub dev: libc::dev_t, pub dev: libc::dev_t,
#[cfg(unix)]
pub uid: u32, pub uid: u32,
#[cfg(unix)]
pub gid: u32, pub gid: u32,
#[cfg(unix)]
pub nlink: u64, pub nlink: u64,
} }
@ -35,22 +30,17 @@ impl Deref for Cha {
impl Default for Cha { impl Default for Cha {
fn default() -> Self { fn default() -> Self {
Self { Self {
kind: ChaKind::DUMMY, kind: ChaKind::DUMMY,
mode: ChaMode::empty(), mode: ChaMode::empty(),
len: 0, len: 0,
atime: None, atime: None,
btime: None, btime: None,
#[cfg(unix)] ctime: None,
ctime: None, mtime: None,
mtime: None, dev: 0,
#[cfg(unix)] uid: 0,
dev: 0, gid: 0,
#[cfg(unix)] nlink: 0,
uid: 0,
#[cfg(unix)]
gid: 0,
#[cfg(unix)]
nlink: 0,
} }
} }
} }
@ -136,17 +126,15 @@ impl Cha {
len: m.len(), len: m.len(),
atime: m.accessed().ok(), atime: m.accessed().ok(),
btime: m.created().ok(), btime: m.created().ok(),
#[cfg(unix)] ctime: unix_either!(
ctime: UNIX_EPOCH.checked_add(Duration::new(m.ctime() as u64, m.ctime_nsec() as u32)), UNIX_EPOCH.checked_add(Duration::new(m.ctime() as u64, m.ctime_nsec() as u32)),
None
),
mtime: m.modified().ok(), mtime: m.modified().ok(),
#[cfg(unix)] dev: unix_either!(m.dev(), 0) as _,
dev: m.dev() as _, uid: unix_either!(m.uid(), 0) as _,
#[cfg(unix)] gid: unix_either!(m.gid(), 0) as _,
uid: m.uid() as _, nlink: unix_either!(m.nlink(), 0) as _,
#[cfg(unix)]
gid: m.gid() as _,
#[cfg(unix)]
nlink: m.nlink() as _,
} }
} }

View file

@ -57,9 +57,9 @@ end
function Linemode:permissions() return self._file.cha:perm() or "" end function Linemode:permissions() return self._file.cha:perm() or "" end
function Linemode:owner() function Linemode:owner()
local user = self._file.cha.uid and ya.user_name(self._file.cha.uid) or self._file.cha.uid local user = ya.user_name 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 local group = ya.group_name and ya.group_name(self._file.cha.gid) or self._file.cha.gid
return string.format("%s:%s", user or "-", group or "-") return string.format("%s:%s", user, group)
end end
function Linemode:redraw() function Linemode:redraw()