Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Modelator data directory after update #151

Merged
merged 2 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix panics at unexpected jars.
16 changes: 10 additions & 6 deletions rs/modelator/src/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,18 @@ pub(crate) fn download_jars_if_necessary<P: AsRef<Path>>(modelator_dir: P) -> Re
}

fn existing_jars<P: AsRef<Path>>(modelator_dir: P) -> Result<HashSet<Jar>, Error> {
let existing_jars: HashSet<_> = list_jars(modelator_dir)?
let existing_jars: HashSet<_> = list_jars(&modelator_dir)?
.into_iter()
.map(|file_name| {
file_name.as_str().try_into().unwrap_or_else(|file_name| {
panic!("[modelator] unexpected jar file: {}", file_name);
})
.flat_map(|file_name| match file_name.as_str().try_into() {
Ok(jar) => Some(Ok(jar)),
Err(file_name) => {
match std::fs::remove_file(modelator_dir.as_ref().to_path_buf().join(file_name)) {
Err(e) => Some(Err(Error::IO(format!("IO error: {:?}", e)))),
_ => None,
}
}
})
.collect();
.collect::<Result<_, Error>>()?;
assert!(
existing_jars.len() <= 3,
"[modelator] at most 3 jar files should have been downloaded"
Expand Down