mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
Use file instead of path
This commit is contained in:
parent
46fea7eafb
commit
9c098166fb
2 changed files with 6 additions and 13 deletions
|
|
@ -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))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)),
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue