Skip to content

Commit

Permalink
(chocolateyGH-585) Force should allow downgrade
Browse files Browse the repository at this point in the history
Previously, force would do everything except for allow downgrades to
occur. There is a special switch for downgrades (`--allow-downgrades`)
and it was required to be passed to allow for a downgrade to occur.
When a user issues the force command they expect that it should
override anything necessary in the install/upgrade, including a
downgrade, because they are forcing it (force means overriding the
behavior of the system). Allow force to override the check for
downgrades.
  • Loading branch information
ferventcoder committed Jan 29, 2016
1 parent 3390867 commit 05ae4dc
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
//todo: handle all

SemanticVersion version = config.Version != null ? new SemanticVersion(config.Version) : null;
if (config.Force) config.AllowDowngrade = true;

IList<string> packageNames = config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().ToList();
if (packageNames.Count == 1)
Expand Down Expand Up @@ -398,7 +399,7 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu

if (installedPackage != null && version != null && version < installedPackage.Version && !config.AllowMultipleVersions && !config.AllowDowngrade)
{
string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade to attempt to install older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to install older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
var nullResult = packageInstalls.GetOrAdd(packageName, new PackageResult(installedPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id)));
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
Expand Down Expand Up @@ -503,6 +504,8 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
var packageInstalls = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);

SemanticVersion version = config.Version != null ? new SemanticVersion(config.Version) : null;
if (config.Force) config.AllowDowngrade = true;

var packageManager = NugetCommon.GetPackageManager(
config,
_nugetLogger,
Expand Down Expand Up @@ -565,7 +568,7 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu

if (version != null && version < installedPackage.Version && !config.AllowMultipleVersions && !config.AllowDowngrade)
{
string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade to attempt to upgrade to older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
string logMessage = "A newer version of {0} (v{1}) is already installed.{2} Use --allow-downgrade or --force to attempt to upgrade to older versions, or use side by side to allow multiple versions.".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
var nullResult = packageInstalls.GetOrAdd(packageName, new PackageResult(installedPackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id)));
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
Expand Down

0 comments on commit 05ae4dc

Please sign in to comment.