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

(#508) Fix multiple packages being uninstall fails if one is a dependency #3142

Merged

Conversation

AdmiringWorm
Copy link
Member

Description Of Changes

The changes in this pull request updates the uninstall behavior by now allowing multiple packages to be uninstalled at the same time, even if one of those packages are a dependency of the other package without it aborting all uninstalls.

To do this, it made it easier to do a custom sort of the packages to uninstall by keeping the order of dependencies being tried in the correct order. Unfortunately this is not always possible, and in these cases a Warning will be outputted to the user without stopping any uninstalls for other packages.

If the package that was warned about is still not uninstalled at the end of the entire execution, this will show up as an error/failure for the package.

Before running the uninstall script or any other uninstall related behavior, we remove any failures on a previously created package result for the package being uninstalled, this inadvertently fixes an issue where failures in a Before Modify script would stop fail the uninstallation even when it had been uninstalled.

Additionally, to make debugging easier it alphabetical sort was added in the report summary of the package, this change also makes the report summary be alphabetically sorted during installations and upgrades.

Motivation and Context

To have uninstallations succeed when it is possible, and to keep some of the backwards compatibility with v1.x

Testing

  1. The E2E tests captures the manual tests done, run these.

Operating Systems Testing

  • Windows 10
  • Windows 2019 (Test kitchen)

Change Types Made

  • Bug fix (non-breaking change).
  • Feature / Enhancement (non-breaking change).
  • Breaking change (fix or feature that could cause existing functionality to change).
  • Documentation changes.
  • PowerShell code changes.

Change Checklist

  • Requires a change to the documentation.
  • Documentation has been updated.
  • Tests to cover my changes, have been added.
  • All new and existing tests passed?
  • PowerShell code changes: PowerShell v2 compatibility checked?

Related Issue

@AdmiringWorm AdmiringWorm self-assigned this Apr 28, 2023
@AdmiringWorm AdmiringWorm requested review from gep13 and vexx32 April 28, 2023 15:09
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

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

Just a minor suggestion based on other tests.

tests/chocolatey-tests/commands/choco-uninstall.Tests.ps1 Outdated Show resolved Hide resolved
After talking with @gep13 it was decided that we should prefer
the usage of `var` instead of using an explicit type when possible.
This commit makes the necessary change to the editor config
to make this a suggestion.
The summary outputted by Chocolatey CLI about installed,
upgrade or installed packages are listed in an unorder list of
package names.

This commit updates the report summary to ensure these are
reported in alphabetical order in each category.
THe uninstall resolver has the potential to throw exceptions when
it finds a package that can not be uninstalled due to it being a
dependency on other packages, as such we need to be able to
handle these scenarios and not stop further processing of the
additional package names.

The changes in this commit adds a try catch block around the resolver,
and if it fails a new package result is created with the reason of the
failure.
There are times where we have created a package result
before attempting the uninstall of a package, when we
come across scenarios for these we need to remove any
previously acquired package to prevent further failures
from occurring during the uninstall, or running of uninstall
scripts.

This was noticed when the user had requested to uninstall
multiple packages, where one package was specified and at
the same time was a dependency on a different package.
When this happens, the first attempt may fail due to it being
a dependency, but once the package referencing this package
is uninstalled while removing all dependencies, the uninstall would
still fail due to the previously cached result would have missing information
about the package.
When we are uninstalling a package, and especially when
one of its dependencies are uninstalled there should be a mention
about what package and its version is being attempted.
This commit adds information about this.
This commit updates the handling of collecting information
about all package names the user has specified on the
command line before attempting to do any uninstalls, or
resolving any of its dependencies.

This allows us to make a better decision about which packages
need to be installed before others.

The code that was added here ensures that if the user specified
two packages, where one was a dependency on the other the package
having the dependency will be attempted to be uninstalled first.
@AdmiringWorm AdmiringWorm force-pushed the PROJ-572/multiple-pkg-uninstalls branch from 2598de0 to 876a50b Compare May 2, 2023 08:53
There are a few E2E tests that we run through test kitchen
that are failing when running on a licensed extension, however
these have not been reproducible outside of test kitchen as of
this date.

As such we mark these tests as only available for Open Source where
they run as expected. Further investigations may be needed to figure
out the root cause of the issue.
@AdmiringWorm AdmiringWorm force-pushed the PROJ-572/multiple-pkg-uninstalls branch from 876a50b to 7cf83cc Compare May 2, 2023 12:36
Copy link
Member

@gep13 gep13 left a comment

Choose a reason for hiding this comment

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

LGTM!

@gep13 gep13 linked an issue May 2, 2023 that may be closed by this pull request
2 tasks
@gep13 gep13 merged commit 254b989 into chocolatey:release/2.0.0 May 2, 2023
@gep13
Copy link
Member

gep13 commented May 2, 2023

@AdmiringWorm thanks for getting this fixed up!

@AdmiringWorm AdmiringWorm deleted the PROJ-572/multiple-pkg-uninstalls branch May 2, 2023 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sort list of installed/upgraded packages
2 participants