Use file instead of path

This commit is contained in:
Akmadan23 2024-01-13 11:37:32 +01:00 committed by sxyazi
parent 46fea7eafb
commit 9c098166fb
No known key found for this signature in database
2 changed files with 6 additions and 13 deletions

View file

@ -1,7 +1,7 @@
use std::{path::Path, str::FromStr}; use std::{path::Path, str::FromStr};
use serde::{Deserialize, Deserializer}; use serde::{Deserialize, Deserializer};
use yazi_shared::MIME_DIR; use yazi_shared::{MIME_DIR, fs::File};
use super::{Color, Style, StyleShadow}; use super::{Color, Style, StyleShadow};
use crate::Pattern; use crate::Pattern;
@ -39,23 +39,16 @@ pub struct Filetype {
} }
impl 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 is_dir = mime == Some(MIME_DIR);
let kind_check = self.kind.as_ref().is_some_and(|t| match t { let kind_check = self.kind.as_ref().is_some_and(|t| match t {
FileKind::Symlink => path.is_symlink(),
#[cfg(unix)] #[cfg(unix)]
FileKind::Executable => { FileKind::Executable => !file.cha.is_dir() && file.cha.permissions & 0o111 != 0,
use std::os::unix::fs::PermissionsExt; FileKind::Symlink => file.cha.is_link(),
let Ok(metadata) = path.metadata() else {
return false;
};
metadata.permissions().mode() & 0o100111 > 0o100000
},
}); });
kind_check 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)) || self.mime.as_ref().zip(mime).map_or(false, |(m, s)| m.matches(s))
} }
} }

View file

@ -91,7 +91,7 @@ impl<'a, 'b> Folder<'a, 'b> {
THEME THEME
.filetypes .filetypes
.iter() .iter()
.find(|&x| x.matches(&file.url, mime)) .find(|&x| x.matches(&file, mime))
.map(|x| Style::from(x.style)), .map(|x| Style::from(x.style)),
) )
}); });