Skip to content

Commit

Permalink
fix update crashing when optional mods is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Commander07 committed May 10, 2024
1 parent 1057745 commit a638730
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ async fn install(installer_profile: InstallerProfile) -> Result<(), String> {
Ok(())
}

fn remove_old_items<T: Downloadable + PartialEq + Clone>(
fn remove_old_items<T: Downloadable + PartialEq + Clone + Debug>(
items: Vec<T>,
installed_items: &Vec<T>,
) -> Vec<T> {
Expand All @@ -1491,13 +1491,12 @@ fn remove_old_items<T: Downloadable + PartialEq + Clone>(
if installed_item.get_version() == item.get_version() {
Some(installed_item.clone())
} else {
let _ = fs::remove_file(installed_item.get_path().as_ref().expect(
&format!(
"Missing 'path' field on installed {} '{}'!",
stringify!(installed_item),
installed_item.get_name()
),
));
if let Some(path) = installed_item.get_path().as_ref() {
let _ = fs::remove_file(path);
} else {
warn!("Missing 'path' field on {installed_item:#?}")
}

Some(item.clone())
}
},
Expand All @@ -1508,11 +1507,11 @@ fn remove_old_items<T: Downloadable + PartialEq + Clone>(
.iter()
.filter(|x| !new_items.contains(x))
.for_each(|x| {
let _ = fs::remove_file(x.get_path().as_ref().expect(&format!(
"Missing 'path' field on installed {} '{}'!",
stringify!(x),
x.get_name()
)));
if let Some(path) = x.get_path().as_ref() {
let _ = fs::remove_file(path);
} else {
warn!("Missing 'path' field on {x:#?}")
}
});
new_items
}
Expand Down

0 comments on commit a638730

Please sign in to comment.