use std::path::{MAIN_SEPARATOR_STR, Path, PathBuf};
use crate::evaluator::Glob;
#[derive(Debug)]
pub struct File {
pub base_path: PathBuf,
pub content: Vec<Glob>,
pub checksum: Vec<u8>,
}
impl File {
#[must_use]
pub fn new(base_path: impl AsRef<Path>, content: Vec<Glob>, checksum: Vec<u8>) -> Self {
Self {
base_path: base_path.as_ref().into(),
content,
checksum,
}
}
pub fn is_ignored(&self, path: impl AsRef<Path>) -> Option<bool> {
let m = path
.as_ref()
.as_os_str()
.to_str()
.unwrap_or_default()
.trim_start_matches(self.base_path.to_str().unwrap_or_default())
.trim_start_matches(MAIN_SEPARATOR_STR);
for glob in self
.content
.iter()
.rev()
{
if let Some(ignored) = glob.is_ignored(m) {
return Some(ignored);
}
}
None
}
}