Created
November 25, 2016 21:57
-
-
Save bluss/6fca0bb18ed603604459bbaaef552d2c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! ```cargo | |
//! [dependencies] | |
//! ignore = "*" | |
//! log = "*" | |
//! ``` | |
#[macro_use] | |
extern crate log; | |
extern crate ignore; | |
use ignore::WalkBuilder; | |
use ignore::WalkState::*; | |
use std::borrow::Cow; | |
use std::sync::mpsc; | |
pub fn get_all_files<'a>(paths: Cow<'a, [&'static str]>, | |
ignored_directories: Cow<'a, [&'static str]>, | |
languages: &mut BTreeMap<LanguageType, Language>) { | |
let (tx, rx) = mpsc::channel(); | |
let ignored_directories = ignored_directories.into_owned(); | |
for path in &*paths { | |
let tx = tx.clone(); | |
let ignored_directories = ignored_directories.clone(); | |
WalkBuilder::new(path).build_parallel().run(move|| { | |
Box::new(move|entry| { | |
let entry = match entry { | |
Ok(entry) => entry, | |
Err(error) => { | |
error!("{}", error.description()); | |
return Continue; | |
} | |
}; | |
let entry = entry.path(); | |
for ig in &ignored_directories { | |
if entry.to_string_lossy().contains(&*ig) { | |
return Continue; | |
} | |
} | |
match entry.metadata() { | |
Ok(metadata) => { | |
if metadata.is_file() { | |
return Continue; | |
} | |
} | |
_ => return Continue, | |
} | |
if entry.to_string_lossy().contains("Makefile") { | |
tx.send((Makefile, entry.to_owned())); | |
} else { | |
if let Some(language) = LanguageType::from_extension(entry) { | |
tx.send((language, entry.to_owned())); | |
} | |
} | |
Continue | |
}) | |
}); | |
} | |
for (language_type, pathbuf) in rx { | |
languages.get_mut(&language_type).unwrap().files.push(pathbuf); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment