This commit is contained in:
sxyazi 2025-09-17 22:55:35 +08:00
parent 7a23f2a4c1
commit 37a78ed7ad
No known key found for this signature in database
5 changed files with 46 additions and 28 deletions

View file

@ -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));

View file

@ -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?;
}

View file

@ -104,8 +104,7 @@ impl State {
async fn skip(&self) -> Result<bool> {
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)
}
}

View file

@ -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<Url<'a>>,
{
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<FileType>) -> 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<Duration> {
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<Duration> {
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<Duration> {
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<Duration> {
if let Some(ctime) = self.ctime {
Ok(ctime.duration_since(UNIX_EPOCH)?)
} else {
bail!("ctime not supported on this platform");
}
}
}

View file

@ -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(),
};