From 37a78ed7ad776f1b4c20041419731f1df835efc6 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Wed, 17 Sep 2025 22:55:35 +0800 Subject: [PATCH] .. --- yazi-binding/src/cha.rs | 16 +++--------- yazi-cli/src/shared/shared.rs | 2 +- yazi-dds/src/state.rs | 3 +-- yazi-fs/src/cha/cha.rs | 43 +++++++++++++++++++++++++++---- yazi-fs/src/provider/sftp/sftp.rs | 10 ++----- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/yazi-binding/src/cha.rs b/yazi-binding/src/cha.rs index 8502603f..f11bfa48 100644 --- a/yazi-binding/src/cha.rs +++ b/yazi-binding/src/cha.rs @@ -66,18 +66,10 @@ impl UserData for Cha { fields.add_field_method_get("is_sticky", |_, me| Ok(me.is_sticky())); 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())) - }); - 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())) - }); - 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("atime", |_, me| Ok(me.atime_dur().ok().map(|d| d.as_secs_f64()))); + fields.add_field_method_get("btime", |_, me| Ok(me.btime_dur().ok().map(|d| d.as_secs_f64()))); + fields.add_field_method_get("ctime", |_, me| Ok(me.ctime_dur().ok().map(|d| d.as_secs_f64()))); + fields.add_field_method_get("mtime", |_, me| Ok(me.mtime_dur().ok().map(|d| d.as_secs_f64()))); 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)); diff --git a/yazi-cli/src/shared/shared.rs b/yazi-cli/src/shared/shared.rs index d12be9b5..76602662 100644 --- a/yazi-cli/src/shared/shared.rs +++ b/yazi-cli/src/shared/shared.rs @@ -34,7 +34,7 @@ pub async fn copy_and_seal(from: &Path, to: &Path) -> io::Result<()> { pub async fn remove_sealed(p: &Path) -> io::Result<()> { #[cfg(windows)] { - let mut perm = Local::metadata(p).await?.permissions(); + let mut perm = tokio::fs::metadata(p).await?.permissions(); perm.set_readonly(false); tokio::fs::set_permissions(p, perm).await?; } diff --git a/yazi-dds/src/state.rs b/yazi-dds/src/state.rs index d7a80c92..879322c9 100644 --- a/yazi-dds/src/state.rs +++ b/yazi-dds/src/state.rs @@ -104,8 +104,7 @@ impl State { async fn skip(&self) -> Result { let cha = Local::symlink_metadata(BOOT.state_dir.join(".dds")).await?; - let modified = - cha.mtime.ok_or_else(|| anyhow!("invalid mtime"))?.duration_since(UNIX_EPOCH)?.as_micros(); + let modified = cha.mtime_dur()?.as_micros(); Ok(modified >= self.last.load(Ordering::Relaxed) as u128) } } diff --git a/yazi-fs/src/cha/cha.rs b/yazi-fs/src/cha/cha.rs index 57dd9b8b..d6ed6b6e 100644 --- a/yazi-fs/src/cha/cha.rs +++ b/yazi-fs/src/cha/cha.rs @@ -1,5 +1,6 @@ -use std::{ffi::OsStr, fs::{FileType, Metadata}, ops::Deref, time::SystemTime}; +use std::{ffi::OsStr, fs::{FileType, Metadata}, ops::Deref, time::{Duration, SystemTime, UNIX_EPOCH}}; +use anyhow::bail; use yazi_macro::{unix_either, win_either}; use yazi_shared::url::Url; @@ -62,16 +63,16 @@ impl Cha { U: Into>, { let url: Url = url.into(); - let mut attached = cha.kind & (ChaKind::HIDDEN | ChaKind::SYSTEM | ChaKind::LINK); + let mut retain = cha.kind & (ChaKind::HIDDEN | ChaKind::SYSTEM | ChaKind::LINK); if cha.is_link() { cha = provider::metadata(url).await.unwrap_or(cha); } if cha.is_link() { - attached |= ChaKind::ORPHAN; + retain |= ChaKind::ORPHAN; } - cha.attach(attached) + cha.attach(retain) } pub fn from_dummy<'a, U>(_url: U, ft: Option) -> Self @@ -95,7 +96,7 @@ impl Cha { fn from_bare(m: &Metadata) -> Self { #[cfg(unix)] - use std::{os::unix::fs::MetadataExt, time::{Duration, UNIX_EPOCH}}; + use std::os::unix::fs::MetadataExt; #[cfg(unix)] let mode = { @@ -165,4 +166,36 @@ impl Cha { #[inline] pub const fn is_dummy(&self) -> bool { self.kind.contains(ChaKind::DUMMY) } + + pub fn atime_dur(&self) -> anyhow::Result { + if let Some(atime) = self.atime { + Ok(atime.duration_since(UNIX_EPOCH)?) + } else { + bail!("atime not supported on this platform"); + } + } + + pub fn mtime_dur(&self) -> anyhow::Result { + if let Some(mtime) = self.mtime { + Ok(mtime.duration_since(UNIX_EPOCH)?) + } else { + bail!("mtime not supported on this platform"); + } + } + + pub fn btime_dur(&self) -> anyhow::Result { + if let Some(btime) = self.btime { + Ok(btime.duration_since(UNIX_EPOCH)?) + } else { + bail!("btime not supported on this platform"); + } + } + + pub fn ctime_dur(&self) -> anyhow::Result { + if let Some(ctime) = self.ctime { + Ok(ctime.duration_since(UNIX_EPOCH)?) + } else { + bail!("ctime not supported on this platform"); + } + } } diff --git a/yazi-fs/src/provider/sftp/sftp.rs b/yazi-fs/src/provider/sftp/sftp.rs index ed5b916f..f3d29751 100644 --- a/yazi-fs/src/provider/sftp/sftp.rs +++ b/yazi-fs/src/provider/sftp/sftp.rs @@ -36,14 +36,8 @@ impl Provider for Sftp { uid: Some(cha.uid), gid: Some(cha.gid), perm: Some(cha.mode.bits() as _), - atime: cha - .atime - .and_then(|t| t.duration_since(UNIX_EPOCH).ok()) - .map(|d| d.as_secs() as u32), - mtime: cha - .mtime - .and_then(|t| t.duration_since(UNIX_EPOCH).ok()) - .map(|d| d.as_secs() as u32), + atime: cha.atime_dur().ok().map(|d| d.as_secs() as u32), + mtime: cha.mtime_dur().ok().map(|d| d.as_secs() as u32), extended: Default::default(), };