Skip to content

Commit

Permalink
(GH-1646) upgrade - skip non-installed packages
Browse files Browse the repository at this point in the history
Previously, if a package was not installed, during upgrade it would
install the package to meet the end state of having a package installed
and up to the latest version. However in some cases, it may be desired
to have the installation skip those packages and continue on, passing a
successful exit code instead of a failure like it would with
`--fail-on-not-installed` (which has similar behavior).

Provide a feature switch `skipPackageUpgradesWhenNotInstalled` that can
be overridden in the upgrade command with either
`--skip-if-not-installed` or `--install-if-not-installed` (the
later only being necessary when the feature switch has been flipped on).
  • Loading branch information
ferventcoder committed Mar 3, 2019
1 parent e4444ad commit 6b446a5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/chocolatey/infrastructure.app/ApplicationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static class Features
public static readonly string StopOnFirstPackageFailure = "stopOnFirstPackageFailure";
public static readonly string UseRememberedArgumentsForUpgrades = "useRememberedArgumentsForUpgrades";
public static readonly string IgnoreUnfoundPackagesOnUpgradeOutdated = "ignoreUnfoundPackagesOnUpgradeOutdated";
public static readonly string SkipPackageUpgradesWhenNotInstalled = "skipPackageUpgradesWhenNotInstalled";
public static readonly string RemovePackageInformationOnUninstall = "removePackageInformationOnUninstall";
public static readonly string LogWithoutColor = "logWithoutColor";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
config.Features.StopOnFirstPackageFailure = set_feature_flag(ApplicationParameters.Features.StopOnFirstPackageFailure, configFileSettings, defaultEnabled: false, description: "Stop On First Package Failure - Stop running install, upgrade or uninstall on first package failure instead of continuing with others. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.4+.");
config.Features.UseRememberedArgumentsForUpgrades = set_feature_flag(ApplicationParameters.Features.UseRememberedArgumentsForUpgrades, configFileSettings, defaultEnabled: false, description: "Use Remembered Arguments For Upgrades - When running upgrades, use arguments for upgrade that were used for installation ('remembered'). This is helpful when running upgrade for all packages. Available in 0.10.4+. This is considered in preview for 0.10.4 and will be flipped to on by default in a future release.");
config.Features.IgnoreUnfoundPackagesOnUpgradeOutdated = set_feature_flag(ApplicationParameters.Features.IgnoreUnfoundPackagesOnUpgradeOutdated, configFileSettings, defaultEnabled: false, description: "Ignore Unfound Packages On Upgrade Outdated - When checking outdated or upgrades, if a package is not found against sources specified, don't report the package at all. Available in 0.10.9+.");
config.Features.SkipPackageUpgradesWhenNotInstalled = set_feature_flag(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configFileSettings, defaultEnabled: false, description: "Skip Packages Not Installed During Upgrade - if a package is not installed, do not install it during the upgrade process. Available in 0.10.12+.");
config.Features.RemovePackageInformationOnUninstall = set_feature_flag(ApplicationParameters.Features.RemovePackageInformationOnUninstall, configFileSettings, defaultEnabled: false, description: "Remove Stored Package Information On Uninstall - When a package is uninstalled, should the stored package information also be removed? Available in 0.10.9+.");
config.Features.LogWithoutColor = set_feature_flag(ApplicationParameters.Features.LogWithoutColor, configFileSettings, defaultEnabled: false, description: "Log without color - Do not show colorization in logging output. Available in 0.10.9+.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,20 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("stoponfirstfailure|stop-on-first-failure|stop-on-first-package-failure",
"Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()),
option => configuration.Features.StopOnFirstPackageFailure = option != null
)
.Add("skip-if-not-installed|only-upgrade-installed|skip-when-not-installed",
"Skip Packages Not Installed - if a package is not installed, do not install it during the upgrade process. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configuration.Features.SkipPackageUpgradesWhenNotInstalled.to_string()),
option => configuration.Features.SkipPackageUpgradesWhenNotInstalled = option != null
)
.Add("install-if-not-installed",
"Install Missing Packages When Not Installed - if a package is not installed, install it as part of running upgrade (typically default behavior). Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with(ApplicationParameters.Features.SkipPackageUpgradesWhenNotInstalled, configuration.Features.SkipPackageUpgradesWhenNotInstalled.to_string()),
option =>
{
if (option != null)
{
configuration.Features.SkipPackageUpgradesWhenNotInstalled = false;
}
})
.Add("exclude-pre|exclude-prerelease|exclude-prereleases",
"Exclude Prerelease - Should prerelease be ignored for upgrades? Will be ignored if you pass `--pre`. Available in 0.10.4+.",
option => configuration.UpgradeCommand.ExcludePrerelease = option != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ public sealed class FeaturesConfiguration
public bool StopOnFirstPackageFailure { get; set; }
public bool UseRememberedArgumentsForUpgrades { get; set; }
public bool IgnoreUnfoundPackagesOnUpgradeOutdated { get; set; }
public bool SkipPackageUpgradesWhenNotInstalled { get; set; }
public bool RemovePackageInformationOnUninstall { get; set; }

//todo remove in 0.11.0
Expand Down
10 changes: 10 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,16 @@ public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(Chocolate
continue;
}

if (config.Features.SkipPackageUpgradesWhenNotInstalled)
{
string warnLogMessage = "{0} is not installed and skip non-installed option selected. Skipping...".format_with(packageName);
var result = packageInstalls.GetOrAdd(packageName, new PackageResult(packageName, null, null));
result.Messages.Add(new ResultMessage(ResultType.Warn, warnLogMessage));
if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, warnLogMessage);

continue;
}

string logMessage = @"{0} is not installed. Installing...".format_with(packageName);

if (config.RegularOutput) this.Log().Warn(ChocolateyLoggers.Important, logMessage);
Expand Down

0 comments on commit 6b446a5

Please sign in to comment.