From c0c0877d42bc4395166de5960fcccce436d75a58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E9=9B=85=20misaki=20masa?= Date: Tue, 23 Sep 2025 15:12:18 +0800 Subject: [PATCH] fix: record the follow state of symlink correctly (#3195) --- yazi-fs/src/cha/cha.rs | 29 +++++++++++++++++------------ yazi-fs/src/cha/kind.rs | 6 +++--- yazi-fs/src/cha/type.rs | 3 --- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/yazi-fs/src/cha/cha.rs b/yazi-fs/src/cha/cha.rs index 4a99d192..875ccc87 100644 --- a/yazi-fs/src/cha/cha.rs +++ b/yazi-fs/src/cha/cha.rs @@ -66,11 +66,9 @@ impl Cha { let mut retain = cha.kind & (ChaKind::HIDDEN | ChaKind::SYSTEM); if cha.is_link() { + retain |= ChaKind::FOLLOW; cha = provider::metadata(url).await.unwrap_or(cha); } - if cha.is_link() { - retain |= ChaKind::ORPHAN; - } cha.attach(retain) } @@ -150,7 +148,17 @@ impl Cha { impl Cha { #[inline] - pub const fn is_hidden(&self) -> bool { + pub fn is_link(self) -> bool { + self.kind.contains(ChaKind::FOLLOW) || *self.mode == ChaType::Link + } + + #[inline] + pub fn is_orphan(self) -> bool { + *self.mode == ChaType::Link && self.kind.contains(ChaKind::FOLLOW) + } + + #[inline] + pub const fn is_hidden(self) -> bool { win_either!( self.kind.contains(ChaKind::HIDDEN) || self.kind.contains(ChaKind::SYSTEM), self.kind.contains(ChaKind::HIDDEN) @@ -158,12 +166,9 @@ impl Cha { } #[inline] - pub const fn is_orphan(&self) -> bool { self.kind.contains(ChaKind::ORPHAN) } + pub const fn is_dummy(self) -> bool { self.kind.contains(ChaKind::DUMMY) } - #[inline] - pub const fn is_dummy(&self) -> bool { self.kind.contains(ChaKind::DUMMY) } - - pub fn atime_dur(&self) -> anyhow::Result { + pub fn atime_dur(self) -> anyhow::Result { if let Some(atime) = self.atime { Ok(atime.duration_since(UNIX_EPOCH)?) } else { @@ -171,7 +176,7 @@ impl Cha { } } - pub fn mtime_dur(&self) -> anyhow::Result { + pub fn mtime_dur(self) -> anyhow::Result { if let Some(mtime) = self.mtime { Ok(mtime.duration_since(UNIX_EPOCH)?) } else { @@ -179,7 +184,7 @@ impl Cha { } } - pub fn btime_dur(&self) -> anyhow::Result { + pub fn btime_dur(self) -> anyhow::Result { if let Some(btime) = self.btime { Ok(btime.duration_since(UNIX_EPOCH)?) } else { @@ -187,7 +192,7 @@ impl Cha { } } - pub fn ctime_dur(&self) -> anyhow::Result { + pub fn ctime_dur(self) -> anyhow::Result { if let Some(ctime) = self.ctime { Ok(ctime.duration_since(UNIX_EPOCH)?) } else { diff --git a/yazi-fs/src/cha/kind.rs b/yazi-fs/src/cha/kind.rs index 2c02a05b..d1d9e367 100644 --- a/yazi-fs/src/cha/kind.rs +++ b/yazi-fs/src/cha/kind.rs @@ -5,9 +5,9 @@ use bitflags::bitflags; bitflags! { #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub struct ChaKind: u8 { - const HIDDEN = 0b0000_0001; - const SYSTEM = 0b0000_0010; - const ORPHAN = 0b0000_0100; + const FOLLOW = 0b0000_0001; + const HIDDEN = 0b0000_0010; + const SYSTEM = 0b0000_0100; const DUMMY = 0b0000_1000; } } diff --git a/yazi-fs/src/cha/type.rs b/yazi-fs/src/cha/type.rs index 9941d6ac..b16a35fe 100644 --- a/yazi-fs/src/cha/type.rs +++ b/yazi-fs/src/cha/type.rs @@ -63,9 +63,6 @@ impl ChaType { #[inline] pub fn is_dir(self) -> bool { self == Self::Dir } - #[inline] - pub fn is_link(self) -> bool { self == Self::Link } - #[inline] pub fn is_block(self) -> bool { self == Self::Block }