Skip to content

Commit bf5d4cf

Browse files
Sam MasonSam Mason
authored andcommitted
Merge commit 'refs/pull/17/head' of https://github.com/olback/library-loader into pr-17
2 parents 90e4720 + 0763e1d commit bf5d4cf

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

ll-core/src/format/extractors/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ pub(super) fn generic_extractor(format: &Format, files: &mut Files, file_path: S
3333

3434
}
3535

36-
if file_path_lower.contains(&format.match_path.to_lowercase()) {
37-
38-
let path = PathBuf::from(file_path);
39-
let base_name = path.file_name().unwrap().to_string_lossy().to_string();
40-
let mut f_data = Vec::<u8>::new();
41-
item.read_to_end(&mut f_data)?;
42-
files.insert(base_name, f_data);
43-
36+
let path = PathBuf::from(file_path);
37+
for paths_to_extract in &format.match_path {
38+
if file_path_lower.contains(paths_to_extract.to_lowercase().as_str()) {
39+
let base_name = path.file_name().unwrap().to_string_lossy().to_string();
40+
let mut f_data = Vec::<u8>::new();
41+
item.read_to_end(&mut f_data)?;
42+
files.insert(base_name, f_data);
43+
}
4444
}
4545

4646
Ok(())

ll-core/src/format/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Format {
1919
pub name: String,
2020
pub ecad: ECAD,
2121
pub create_folder: bool,
22-
match_path: &'static str,
22+
match_path: Vec<&'static str>,
2323
ignore: Vec<&'static str>
2424
}
2525

@@ -42,28 +42,28 @@ impl Format {
4242
name: f,
4343
ecad: ECAD::EAGLE,
4444
create_folder: false,
45-
match_path: "EAGLE",
45+
match_path: vec!["EAGLE/", "/3D/"],
4646
ignore: vec!["Readme.html"]
4747
},
4848
"easyeda" => Self {
4949
name: f,
5050
ecad: ECAD::EASYEDA,
5151
create_folder: false,
52-
match_path: "EasyEDA",
52+
match_path: vec!["EasyEDA/", "/3D/"],
5353
ignore: vec!["Readme.html"]
5454
},
5555
"kicad" => Self {
5656
name: f,
5757
ecad: ECAD::KICAD,
5858
create_folder: true,
59-
match_path: "KiCad",
59+
match_path: vec!["KiCad/", "/3D/"],
6060
ignore: vec![]
6161
},
6262
"zip" => Self {
6363
name: f,
6464
ecad: ECAD::ZIP,
6565
create_folder: false,
66-
match_path: "",
66+
match_path: vec![""],
6767
ignore: vec![]
6868
},
6969
_ => {

ll-core/src/watcher.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,20 @@ impl Watcher {
186186

187187
}
188188

189-
fn handle_file<P: Into<PathBuf>>(&self, path: P) -> LLResult<String> {
190-
191-
let epw = Epw::from_file(path)?;
192-
let res = &self.cse.get(epw)?;
193-
res.save()
194-
189+
fn handle_file(&self, path: &PathBuf) -> LLResult<String> {
190+
let extension = path.extension().and_then(|ext| { ext.to_str() });
191+
match extension {
192+
Some(s) => if s.eq_ignore_ascii_case("zip") {
193+
let epw = Epw::from_file(path)?;
194+
let res = &self.cse.get(epw)?;
195+
res.save()
196+
} else {
197+
Err(LLError::new(format!("=> Ignoring non-zip: {}", path.to_str().unwrap())))
198+
}
199+
None => {
200+
Err(LLError::new(format!("=> Ignoring: {}", path.to_str().unwrap())))
201+
}
202+
}
195203
}
196204

197205
}

0 commit comments

Comments
 (0)