From 9c098166fb4ed497e62643a6ee5bbb8613fa092e Mon Sep 17 00:00:00 2001 From: Akmadan23 Date: Sat, 13 Jan 2024 11:37:32 +0100 Subject: [PATCH] Use file instead of path --- yazi-config/src/theme/filetype.rs | 17 +++++------------ yazi-fm/src/lives/folder.rs | 2 +- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/yazi-config/src/theme/filetype.rs b/yazi-config/src/theme/filetype.rs index 17c4be83..f79bdf66 100644 --- a/yazi-config/src/theme/filetype.rs +++ b/yazi-config/src/theme/filetype.rs @@ -1,7 +1,7 @@ use std::{path::Path, str::FromStr}; use serde::{Deserialize, Deserializer}; -use yazi_shared::MIME_DIR; +use yazi_shared::{MIME_DIR, fs::File}; use super::{Color, Style, StyleShadow}; use crate::Pattern; @@ -39,23 +39,16 @@ pub struct Filetype { } impl Filetype { - pub fn matches(&self, path: &Path, mime: Option<&str>) -> bool { + pub fn matches(&self, file: &File, mime: Option<&str>) -> bool { let is_dir = mime == Some(MIME_DIR); let kind_check = self.kind.as_ref().is_some_and(|t| match t { - FileKind::Symlink => path.is_symlink(), #[cfg(unix)] - FileKind::Executable => { - use std::os::unix::fs::PermissionsExt; - let Ok(metadata) = path.metadata() else { - return false; - }; - - metadata.permissions().mode() & 0o100111 > 0o100000 - }, + FileKind::Executable => !file.cha.is_dir() && file.cha.permissions & 0o111 != 0, + FileKind::Symlink => file.cha.is_link(), }); kind_check - || self.name.as_ref().is_some_and(|n| n.match_path(path, is_dir)) + || self.name.as_ref().is_some_and(|n| n.match_path(&file.url, is_dir)) || self.mime.as_ref().zip(mime).map_or(false, |(m, s)| m.matches(s)) } } diff --git a/yazi-fm/src/lives/folder.rs b/yazi-fm/src/lives/folder.rs index d9c6531f..0909453e 100644 --- a/yazi-fm/src/lives/folder.rs +++ b/yazi-fm/src/lives/folder.rs @@ -91,7 +91,7 @@ impl<'a, 'b> Folder<'a, 'b> { THEME .filetypes .iter() - .find(|&x| x.matches(&file.url, mime)) + .find(|&x| x.matches(&file, mime)) .map(|x| Style::from(x.style)), ) });