Skip to content
Draft
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
6 changes: 6 additions & 0 deletions src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ impl Manifestation {

// Uninstall components
for component in update.components_to_uninstall {
// If there are no components installed, we don't need to keep
// checking, we can simply exit the loop earlier.
if self.installation.list()?.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in principle this fix is correct, thanks!

However, isn't .list() doing a FS read every time in this loop? I'd imagine the result of .installation.list() to be perfectly predictable (don't care about ToC/ToU for now), so may I ask what do we have in .components_to_uninstall and .installation.list() here?

In other words, could these be two sets of elements of the same format, so that we can make a difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, .list() implies a FS read, so a reasonable solution may be to enter the loop only if .list() is not empty (i.e., by adding a conditional check before the loop).

so may I ask what do we have in .components_to_uninstall and .installation.list() here?

In this case, as the toolchain was not installed, .components_to_uninstall was set to all the 6 components (see here), and .installation.list() was empty.

That said, I think a better approach would be to restrict the components_to_uninstall vector to only include components that actually exist; this comment may be misleading in that regard.
This would eliminate the need for the additional check and further simplify the uninstall_component function.

What do you think about this approach?

info!("recovering from a partially installed toolchain");
break;
}
match (implicit_modify, &component.target) {
(true, Some(t)) if t != &self.target_triple => {
info!(
Expand Down