Look for .ignore files in subfolders of watched paths

This commit is contained in:
Chris Nicholls 2020-03-09 10:59:02 +00:00
parent 0175e071e1
commit 2d29a7d7c4

View file

@ -1,4 +1,5 @@
extern crate globset;
extern crate walkdir;
use globset::{GlobBuilder, GlobSet, GlobSetBuilder};
use std::collections::HashSet;
@ -6,6 +7,7 @@ use std::fs;
use std::io;
use std::io::Read;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
pub struct Ignore {
files: Vec<IgnoreFile>,
@ -48,6 +50,7 @@ pub fn load(paths: &[PathBuf]) -> Ignore {
for path in paths {
let mut p = path.to_owned();
// walk up to root
loop {
if !checked_dirs.contains(&p) {
checked_dirs.insert(p.clone());
@ -69,6 +72,22 @@ pub fn load(paths: &[PathBuf]) -> Ignore {
p.pop();
}
//also look in subfolders
for entry in WalkDir::new(path)
.into_iter()
.filter_map(Result::ok)
.filter(|e| e.file_type().is_file())
.filter(|e| e.file_name() == ".ignore")
{
let ignore_path = entry.path();
if let Ok(f) = IgnoreFile::new(&ignore_path) {
debug!("Loaded {:?}", ignore_path);
files.push(f);
} else {
debug!("Unable to load {:?}", ignore_path);
}
}
}
Ignore::new(files)