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

(#1479) Add ability to use remembered arguments during uninstall #2648

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

TheCakeIsNaOH
Copy link
Member

@TheCakeIsNaOH TheCakeIsNaOH commented Mar 10, 2022

Description Of Changes

This adds the ability for remembered arguments to be used during uninstall.

Similarly to using remembered argument for upgrades, a feature has been added, UseRememberedArgumentsForUninstalls, and --ignore-remembered-arguments/--use-remembered-arguments argument have been added to the uninstall command.

The set_package_config_for_upgrade has been renamed and some other changes were made to update it to prepare it to be used for setting the config for both upgrade and uninstall. The implementation of the feature uses the same method the upgrade command does. Remembered install arguments (--install-arguments=) are ignored, so they do not overwrite --uninstall-arguments=, as both use the same internal config value.

To prevent an issue like #1443, a reset config action has also been added to uninstall_run, just like the one added to upgrade_run in #2484.

Motivation and Context

When creating a package that will copy file(s) to a location that is specified via a package parameter, or adding a location to the $env:path, there is not an easy way to save that location, so it can be removed during uninstall. It is possible to save it via a text file or similar, but there is not a standardized way to do so.

Having argument, including package parameters be remembered during uninstall allows for an easy fix to this situation. The uninstall script can get those parameters, and therefore get the location(s) that need to be removed. This also applies to any other behavior set via a parameter that need to be undone during the uninstall script.

Any --install-arguments= are not remembered during uninstall because they can conflict with uninstall arguments, as the available set of install and uninstall arguments are different in most cases.

Testing

Build choco, run the integration tests, and (if required), copy the context directory from the integration test to the directory you are testing from.

  1. Check that the feature works:
.\choco.exe feature enable -n UseRememberedArgumentsForUninstalls
.\choco.exe install upgradepackage --version=1.0.0 --source=.\context --package-parameters="/PKGPARAM" --yes
.\choco.exe uninstall upgradepackage --verbose --debug --yes

Validate that during the uninstall output, the chocolateyUninstall.ps1 is called with /PKGPARAM included.

  1. Check that the ignore switch works:
.\choco.exe feature enable -n UseRememberedArgumentsForUninstalls
.\choco.exe install upgradepackage --version=1.0.0 --source=.\context --package-parameters="/PKGPARAM" --yes
.\choco.exe uninstall upgradepackage --verbose --debug --ignore-remembered-arguments --yes

Validate that during the uninstall output, the chocolateyUninstall.ps1 is called with /PKGPARAM NOT included.

  1. Check that --ia are not used:
.\choco.exe feature enable -n UseRememberedArgumentsForUninstalls
.\choco.exe install upgradepackage --version=1.0.0 --source=.\context --ia="installArg" --yes
.\choco.exe uninstall upgradepackage --verbose --debug --yes

Validate that during the uninstall output, the chocolateyUninstall.ps1 is called with installArg NOT included.

  1. Check that the use switch works:
.\choco.exe feature disable -n UseRememberedArgumentsForUninstalls
.\choco.exe install upgradepackage --version=1.0.0 --source=.\context --package-parameters="/PKGPARAM" --yes
.\choco.exe uninstall upgradepackage --verbose --debug --yes --use-remembered-arguments

Validate that during the uninstall output, the chocolateyUninstall.ps1 is called with /PKGPARAM included.

  1. Check that arguments are not reused:
.\choco.exe feature enable -n UseRememberedArgumentsForUninstalls
.\choco.exe install installpackage --version=1.0.0 --source=.\context --package-parameters="/PKGPARAM" --yes
.\choco.exe install upgradepackage --version=1.0.0 --source=.\context --yes
.\choco.exe uninstall installpackage upgradepackage --verbose --debug --yes

Validate that the installpackage uninstall script is called with /PKGPARAM but the upgradepackage uninstall script is called without it.

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)

Related Issue

Fixes #1479
Based on/Depends on #3003

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.
  • N/A PowerShell v2 compatibility checked.

@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch 2 times, most recently from cef63cd to a86fbe8 Compare March 11, 2022 01:54
@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as ready for review March 11, 2022 01:55
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch from a86fbe8 to 4cf4fbe Compare March 21, 2022 16:31
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch from 4cf4fbe to 627bedb Compare June 27, 2022 14:57
@coveralls
Copy link

Coverage Status

Coverage increased (+0.008%) to 28.586% when pulling 627bedb on TheCakeIsNaOH:uninstall-remembered-arguments into 6f3fc15 on chocolatey:develop.

@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as draft September 23, 2022 04:50
@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as ready for review September 25, 2022 01:01
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch from 627bedb to 8116f2b Compare September 25, 2022 01:01
@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as draft January 27, 2023 22:32
@TheCakeIsNaOH
Copy link
Member Author

This is draft until #3003 is merged/closed, as the implementation of this depends on what happens with that PR.

@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch from 8116f2b to 8919ee3 Compare January 10, 2024 01:16
@TheCakeIsNaOH
Copy link
Member Author

Rebased on #3003

@TheCakeIsNaOH TheCakeIsNaOH marked this pull request as ready for review January 10, 2024 01:16
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch from 8919ee3 to 3823ea0 Compare January 10, 2024 01:27
This helps ensure that package IDs are handled in a case
insensitive manner.
This allows overriding of remembered package parameters, install
arguments, cache location and execution timeout during upgrade.
So a user can pass in different package parameters or arguments
without having to completely reinstall the package or turn off
remembered arguments.

Switch arguments cannot be checked, because the lack of a switch
normally would mean that they are just relying on the remembered args
to remember it, so there is no way to determine if an override of the
remembered args is appropriate.
…ration

This adds a new method, GetPackageConfigFromRememberedArguments which
is similar to SetConfigFromRememberedArguments, but operates using a
different method. First, a OptionSet is set up, so only the config
that is passed in is modified, instead of the config that the global
options parser was set with with. Second, it returns the modified
configuration instead of the original configuration, because it is the
local configuration being modified. Third, it has a more general name
and changes log messages to be more general, so it later can more
easily be reused for uninstall and export.

This change fixes remembered arguments when Chocolatey is used as a
library, like in ChocolateyGUI, where the config that is passed to
the install_run method is not necessarily the same config object that
was used to set up the global argument parser.

The downside of using a new commandline parser is that it opens up the
possibility of drift between the upgrade/global arguments and this
added parser. However, this is not an issue because the format of the
saved arguments is known, and any added arguments there would not work
without being added here as well, which would be picked up during
development.
This brings out the functionality from the
set_package_config_for_upgrade method to a more generic name, and adds
in another parameter to prepare for setting remembered args for
uninstall as well as upgrade. It also updates the logging and comments
to make them generic for both upgrades and uninstalls.

An alias/forwarding method is added for backwards compatibility.
Similar to the UseRememberedArgumentsForUpgrade feature, this will be
used to toggle if the remembered arguments are used during uninstall.
This adds the ability for the remembered argument to be reused for
uninstalls. It can be controlled via the userememberedargs and
ignorerememberedargs arguments, or via the previously added feature.
@TheCakeIsNaOH TheCakeIsNaOH force-pushed the uninstall-remembered-arguments branch from 3823ea0 to 75298e2 Compare April 28, 2024 02:59
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.

Please persist package installation parameters for uninstall scripts
2 participants