order adapters according to original priorities

This commit is contained in:
phiresky 2019-06-11 14:40:58 +02:00
parent bca435557b
commit c27bc4edf2
2 changed files with 23 additions and 7 deletions

View File

@ -101,6 +101,7 @@ pub fn extension_to_regex(extension: &str) -> Regex {
} }
pub fn get_adapters() -> Vec<Rc<dyn FileAdapter>> { pub fn get_adapters() -> Vec<Rc<dyn FileAdapter>> {
// order in descending priority
let adapters: Vec<Rc<dyn FileAdapter>> = vec![ let adapters: Vec<Rc<dyn FileAdapter>> = vec![
Rc::new(ffmpeg::FFmpegAdapter), Rc::new(ffmpeg::FFmpegAdapter),
Rc::new(pandoc::PandocAdapter), Rc::new(pandoc::PandocAdapter),
@ -165,6 +166,8 @@ pub fn adapter_matcher<T: AsRef<str>>(
slow: bool, slow: bool,
) -> Fallible<impl Fn(FileMeta) -> Option<Rc<dyn FileAdapter>>> { ) -> Fallible<impl Fn(FileMeta) -> Option<Rc<dyn FileAdapter>>> {
let adapters = get_adapters_filtered(adapter_names)?; let adapters = get_adapters_filtered(adapter_names)?;
// need order later
let adapter_names: Vec<String> = adapters.iter().map(|e| e.metadata().name.clone()).collect();
let mut fname_regexes = vec![]; let mut fname_regexes = vec![];
let mut mime_regexes = vec![]; let mut mime_regexes = vec![];
for adapter in adapters.into_iter() { for adapter in adapters.into_iter() {
@ -195,13 +198,26 @@ pub fn adapter_matcher<T: AsRef<str>>(
vec![] vec![]
}; };
if fname_matches.len() + mime_matches.len() > 1 { if fname_matches.len() + mime_matches.len() > 1 {
eprintln!("Found multiple adapters for {}:", meta.lossy_filename); // get first according to original priority list...
for mmatch in mime_matches.iter() { let fa = fname_matches.iter().map(|e| fname_regexes[*e].1.clone());
eprintln!(" - {}", mime_regexes[*mmatch].1.metadata().name); let fb = mime_matches.iter().map(|e| mime_regexes[*e].1.clone());
} let mut v = vec![];
for fmatch in fname_matches.iter() { v.extend(fa);
eprintln!(" - {}", fname_regexes[*fmatch].1.metadata().name); v.extend(fb);
v.sort_by_key(|e| {
(adapter_names
.iter()
.position(|r| r == &e.metadata().name)
.expect("impossib7"))
});
eprintln!(
"Warning: found multiple adapters for {}:",
meta.lossy_filename
);
for mmatch in v.iter() {
eprintln!(" - {}", mmatch.metadata().name);
} }
return Some(v[0].clone());
} }
if mime_matches.is_empty() { if mime_matches.is_empty() {
if fname_matches.is_empty() { if fname_matches.is_empty() {

View File

@ -18,7 +18,7 @@ lazy_static! {
.iter() .iter()
.map(|s| FastMatcher::FileExtension(s.to_string())) .map(|s| FastMatcher::FileExtension(s.to_string()))
.collect(), .collect(),
slow_matchers: None slow_matchers: Some(vec![SlowMatcher::MimeType("application/zip".to_owned())])
}; };
} }
#[derive(Default)] #[derive(Default)]