Skip to content

Commit

Permalink
(chocolatey#2787) Deprecate side-by-side installations
Browse files Browse the repository at this point in the history
This commit makes the necessary changes to deprecate
side by side installations in the Chocolatey CLI codebase as well
as warn the users about any installations for side-by-side.
Including if the user have side-by-side installations already
installed on their system.
  • Loading branch information
AdmiringWorm committed Sep 15, 2022
1 parent 2d2490c commit 09b2473
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"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.",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("i|ignoredependencies|ignore-dependencies",
"IgnoreDependencies - Ignore dependencies when installing package(s). Defaults to false.",
Expand Down Expand Up @@ -254,6 +254,8 @@ prompt. In most cases you can still pass options and switches with one
Starting in v2.0.0 the shortcut `cinst` will be removed and can not be used
to install packages anymore. We recommend you make sure that you always
use the full command going forward (`choco install`).
Side by side installations has been deprecated and will be removed in v2.0.0.
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"Apply Package Parameters To Dependencies - Should package parameters be applied to dependent packages? Defaults to false.",
option => configuration.ApplyPackageParametersToDependencies = 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.",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("x|forcedependencies|force-dependencies|removedependencies|remove-dependencies",
"RemoveDependencies - Uninstall dependencies when uninstalling package(s). Defaults to false.",
Expand Down Expand Up @@ -208,6 +208,8 @@ to determine how to automatically uninstall software.
Starting in v2.0.0 the shortcut `cuninst` will be removed and can not be used
to uninstall packages anymore. We recommend you make sure that you always
use the full command going forward (`choco uninstall`).
Side by side installations has been deprecated and support for uninstalling such packages will be removed in v2.0.0.
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
"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.",
"AllowMultipleVersions - Should multiple versions of a package be installed? Defaults to false. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("i|ignoredependencies|ignore-dependencies",
"IgnoreDependencies - Ignore dependencies when upgrading package(s). Defaults to false.",
Expand Down Expand Up @@ -285,6 +285,8 @@ prompt. In most cases you can still pass options and switches with one
Starting in v2.0.0 the shortcut `cup` will be removed and can not be used
to upgrade or install packages anymore. We recommend you make sure that you always
use the full command going forward (`choco upgrade`).
Side by side installations has been deprecated and will be removed in v2.0.0.
");

"chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ private void append_output(StringBuilder propertyValues, string append)
public bool ApplyPackageParametersToDependencies { get; set; }
public bool ApplyInstallArgumentsToDependencies { get; set; }
public bool IgnoreDependencies { get; set; }

[Obsolete("Side by Side installation is deprecated, and is pending removal in v2.0.0")]
public bool AllowMultipleVersions { get; set; }
public bool AllowDowngrade { get; set; }
public bool ForceDependencies { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace chocolatey.infrastructure.app.domain
{
using System;
using NuGet;

public sealed class ChocolateyPackageInformation
Expand All @@ -31,6 +32,8 @@ public ChocolateyPackageInformation(IPackage package)
public string Arguments { get; set; }
public SemanticVersion VersionOverride { get; set; }
public bool HasSilentUninstall { get; set; }

[Obsolete("Side by side installations are deprecated, with removal pending in v2.0.0")]
public bool IsSideBySide { get; set; }
public bool IsPinned { get; set; }
public string ExtraInformation { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace chocolatey.infrastructure.app.nuget
{
using System;
using System.IO;
using NuGet;

Expand All @@ -24,8 +25,16 @@ namespace chocolatey.infrastructure.app.nuget
public sealed class ChocolateyPackagePathResolver : DefaultPackagePathResolver
{
private readonly IFileSystem _nugetFileSystem;

[Obsolete("Side by Side installations are deprecated, and is pending removal in v2.0.0")]
public bool UseSideBySidePaths { get; set; }

public ChocolateyPackagePathResolver(IFileSystem nugetFileSystem)
: this(nugetFileSystem, useSideBySidePaths: false)
{
}

[Obsolete("Initializing using side by side installation enabled is deprecated. Use overload without useSideBySidePaths instead.")]
public ChocolateyPackagePathResolver(IFileSystem nugetFileSystem, bool useSideBySidePaths)
: base(nugetFileSystem, useSideBySidePaths)
{
Expand All @@ -47,6 +56,7 @@ public override string GetPackageDirectory(string packageId, SemanticVersion ver
return GetPackageDirectory(packageId, version, UseSideBySidePaths);
}

[Obsolete("Side by Side installations are deprecated, and is pending removal in v2.0.0")]
public string GetPackageDirectory(string packageId, SemanticVersion version, bool useVersionInPath)
{
string directory = packageId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
namespace chocolatey.infrastructure.app.services
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using configuration;
Expand All @@ -42,6 +43,10 @@ public class ChocolateyPackageInformationService : IChocolateyPackageInformation
private const string EXTRA_FILE = ".extra";
private const string VERSION_OVERRIDE_FILE = ".version";

// We need to store the package identifiers we have warned about
// to prevent duplicated outputs.
private HashSet<string> _deprecationWarning = new HashSet<string>();

public ChocolateyPackageInformationService(IFileSystem fileSystem, IRegistryService registryService, IFilesService filesService)
{
_fileSystem = fileSystem;
Expand Down Expand Up @@ -141,6 +146,19 @@ has errored attempting to read it. This file will be renamed to
var extraInfoFile = _fileSystem.combine_paths(pkgStorePath, EXTRA_FILE);
if (_fileSystem.file_exists(extraInfoFile)) packageInformation.ExtraInformation = _fileSystem.read_file(extraInfoFile);

if (packageInformation.IsSideBySide && !_deprecationWarning.Contains(package.Id))
{
var logger = _config.RegularOutput ?
logging.ChocolateyLoggers.Important :
logging.ChocolateyLoggers.LogFileOnly;

this.Log().Warn(logger, @"
{0} has been installed as a side by side installation.
Side by side installations are deprecated and is pending removal in v2.0.0.", package.Id);

_deprecationWarning.Add(package.Id);
}

var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE);
if (_fileSystem.file_exists(versionOverrideFile))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,11 @@ private string capture_arguments(ChocolateyConfiguration config, PackageResult p

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config)
{
if (config.AllowMultipleVersions)
{
this.Log().Warn(ChocolateyLoggers.Important, "Installing the same package with multiple versions is deprecated and will be removed in v2.0.0.");
}

this.Log().Info(is_packages_config_file(config.PackageNames) ? @"Installing from config file:" : @"Installing the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

Expand Down Expand Up @@ -808,6 +813,11 @@ public void upgrade_noop(ChocolateyConfiguration config)

public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfiguration config)
{
if (config.AllowMultipleVersions)
{
this.Log().Warn(ChocolateyLoggers.Important, "Upgrading the same package with multiple versions is deprecated and will be removed in v2.0.0.");
}

this.Log().Info(@"Upgrading the following packages:");
this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames));

Expand Down
11 changes: 11 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,15 @@ public virtual ConcurrentDictionary<string, PackageResult> get_outdated(Chocolat
packageResult.Messages.Add(new ResultMessage(ResultType.Note, logMessage));

this.Log().Info("{0}|{1}|{2}|{3}".format_with(installedPackage.Id, installedPackage.Version, latestPackage.Version, isPinned.to_string().to_lower()));

if (pkgInfo.IsSideBySide)
{
var deprecationMessage = @"
{0} v{1} has been installed as a side by side installation.
Side by side installations are deprecated and is pending removal in v2.0.0".format_with(installedPackage.Id, installedPackage.Version);

packageResult.Messages.Add(new ResultMessage(ResultType.Warn, deprecationMessage));
}
}

return outdatedPackages;
Expand Down Expand Up @@ -1267,6 +1276,8 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
{
var pkg = e.Package;

// TODO: Removal special handling for SxS packages once we hit v2.0.0

// this section fires twice sometimes, like for older packages in a sxs install...
var packageResult = packageUninstalls.GetOrAdd(pkg.Id.to_lower() + "." + pkg.Version.to_string(), new PackageResult(pkg, e.InstallPath));
packageResult.InstallLocation = e.InstallPath;
Expand Down

0 comments on commit 09b2473

Please sign in to comment.