use std::path::{Path, PathBuf};
use crate::FileEvent;
use crate::filters::{self, PathOptions};
use super::Monitor;
impl Monitor {
pub(crate) fn opts_for_path(&self, path: &Path) -> Vec<&PathOptions> {
self.monitored_entries
.iter()
.filter(|(p, _)| p == path)
.map(|(_, o)| o)
.collect()
}
pub(crate) fn first_opt_for_path(&self, path: &Path) -> Option<&PathOptions> {
self.monitored_entries
.iter()
.find(|(p, _)| p == path)
.map(|(_, o)| o)
}
#[cfg(test)]
pub(crate) fn should_output(&self, event: &FileEvent) -> bool {
let opts = self.get_matching_path_options(&event.path);
filters::should_output(opts, event)
}
pub(crate) fn should_output_for_opts(&self, event: &FileEvent, opts: &PathOptions) -> bool {
filters::should_output(Some(opts), event)
}
pub(crate) fn matching_path(&self, path: &Path) -> Option<&PathBuf> {
filters::matching_path(&self.paths, &self.canonical_paths, path)
}
#[cfg(test)]
pub(crate) fn is_path_in_scope(&self, path: &Path) -> bool {
filters::is_path_in_scope(
&self.paths,
&self.monitored_entries,
&self.canonical_paths,
path,
)
}
pub(crate) fn is_path_in_scope_for_opts(&self, event_path: &Path, opts: &PathOptions) -> bool {
self.monitored_entries.iter().any(|(mp, stored_opts)| {
if stored_opts.cmd != opts.cmd || stored_opts.recursive != opts.recursive {
return false;
}
if opts.recursive {
event_path.starts_with(mp)
} else {
event_path == mp.as_path() || event_path.parent() == Some(mp.as_path())
}
})
}
}