aboutsummaryrefslogtreecommitdiff
path: root/crates/vfs-notify/src/include.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/vfs-notify/src/include.rs')
-rw-r--r--crates/vfs-notify/src/include.rs42
1 files changed, 0 insertions, 42 deletions
diff --git a/crates/vfs-notify/src/include.rs b/crates/vfs-notify/src/include.rs
deleted file mode 100644
index 59da3d77a..000000000
--- a/crates/vfs-notify/src/include.rs
+++ /dev/null
@@ -1,42 +0,0 @@
1//! See `Include`.
2use std::convert::TryFrom;
3
4use globset::{Glob, GlobSet, GlobSetBuilder};
5use paths::{RelPath, RelPathBuf};
6
7/// `Include` is the opposite of .gitignore.
8///
9/// It describes the set of files inside some directory.
10///
11/// The current implementation is very limited, it allows including file globs
12/// and recursively excluding directories.
13#[derive(Debug, Clone)]
14pub(crate) struct Include {
15 include_files: GlobSet,
16 exclude_dirs: Vec<RelPathBuf>,
17}
18
19impl Include {
20 pub(crate) fn new(include: Vec<String>) -> Include {
21 let mut include_files = GlobSetBuilder::new();
22 let mut exclude_dirs = Vec::new();
23
24 for glob in include {
25 if glob.starts_with("!/") {
26 if let Ok(path) = RelPathBuf::try_from(&glob["!/".len()..]) {
27 exclude_dirs.push(path)
28 }
29 } else {
30 include_files.add(Glob::new(&glob).unwrap());
31 }
32 }
33 let include_files = include_files.build().unwrap();
34 Include { include_files, exclude_dirs }
35 }
36 pub(crate) fn include_file(&self, path: &RelPath) -> bool {
37 self.include_files.is_match(path)
38 }
39 pub(crate) fn exclude_dir(&self, path: &RelPath) -> bool {
40 self.exclude_dirs.iter().any(|excluded| path.starts_with(excluded))
41 }
42}