Skip to content

Instantly share code, notes, and snippets.

@bluss
Created November 25, 2016 22:02
Show Gist options
  • Select an option

  • Save bluss/9151ee3d8f16927082b4f02cab627316 to your computer and use it in GitHub Desktop.

Select an option

Save bluss/9151ee3d8f16927082b4f02cab627316 to your computer and use it in GitHub Desktop.
//! ```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;
use std::collections::BTreeMap;
use std::error::Error;
#[derive(PartialOrd, Ord, PartialEq, Eq)]
pub enum LanguageType {
Makefile,
}
use self::LanguageType::*;
pub struct Language;
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 {
panic!()
}
Continue
})
});
}
for (language_type, pathbuf) in rx {
panic!()
//languages.get_mut(&language_type).unwrap().files.push(pathbuf);
}
}
fn main() { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment