Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
* stable:
  (chocolateyGH-365) Exit Non-zero if newer version installed
  • Loading branch information
ferventcoder committed Aug 17, 2015
2 parents 94ca753 + ad6de62 commit 8a3b1f8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfigurati
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("allowdowngrade|allow-downgrade",
"AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.",
option => configuration.AllowDowngrade = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.",
option => configuration.AllowMultipleVersions = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("params=|parameters=|pkgparameters=|packageparameters=|package-parameters=",
"PackageParameters - Parameters to pass to the package. Defaults to unspecified.",
option => configuration.PackageParameters = option.remove_surrounding_quotes())
.Add("allowdowngrade|allow-downgrade",
"AllowDowngrade - Should an attempt at downgrading be allowed? Defaults to false.",
option => configuration.AllowDowngrade = option != null)
.Add("m|sxs|sidebyside|side-by-side|allowmultiple|allow-multiple|allowmultipleversions|allow-multiple-versions",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false.",
option => configuration.AllowMultipleVersions = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ private void append_output(StringBuilder propertyValues, string append)
public string PackageParameters { get; set; }
public bool IgnoreDependencies { get; set; }
public bool AllowMultipleVersions { get; set; }
public bool AllowDowngrade { get; set; }
public bool ForceDependencies { get; set; }

/// <summary>
Expand Down
22 changes: 20 additions & 2 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
version = installedPackage.Version;
}

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);
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);
continue;
}

IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageName, version, config.Prerelease, allowUnlisted: false);
if (availablePackage == null)
{
Expand Down Expand Up @@ -479,6 +488,15 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
continue;
}

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);
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);
continue;
}

var pkgInfo = _packageInfoService.get_package_information(installedPackage);
bool isPinned = pkgInfo != null && pkgInfo.IsPinned;

Expand Down Expand Up @@ -519,7 +537,7 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu

var packageResult = packageInstalls.GetOrAdd(packageName, new PackageResult(availablePackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, availablePackage.Id)));

if ((installedPackage.Version > availablePackage.Version))
if (installedPackage.Version > availablePackage.Version && !config.AllowDowngrade)
{
string logMessage = "{0} v{1} is newer than the most recent.{2} You must be smarter than the average bear...".format_with(installedPackage.Id, installedPackage.Version, Environment.NewLine);
packageResult.Messages.Add(new ResultMessage(ResultType.Inconclusive, logMessage));
Expand Down Expand Up @@ -569,7 +587,7 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
if (config.RegularOutput) this.Log().Info(logMessage);
}

if ((availablePackage.Version > installedPackage.Version) || config.Force)
if ((availablePackage.Version > installedPackage.Version) || config.Force || (availablePackage.Version < installedPackage.Version && config.AllowDowngrade))
{
if (availablePackage.Version > installedPackage.Version)
{
Expand Down

0 comments on commit 8a3b1f8

Please sign in to comment.