Skip to content

Commit

Permalink
(chocolatey#2788) Remove side-by-side installs
Browse files Browse the repository at this point in the history
This functionality is deprecated and we're removing it for v2.0.
  • Loading branch information
vexx32 committed Mar 16, 2023
1 parent 8021903 commit 9a7b44d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.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. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("i|ignoredependencies|ignore-dependencies",
"IgnoreDependencies - Ignore dependencies when installing package(s). Defaults to false.",
option => configuration.IgnoreDependencies = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
.Add("paramsglobal|params-global|packageparametersglobal|package-parameters-global|applyparamstodependencies|apply-params-to-dependencies|apply-package-parameters-to-dependencies",
"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. (DEPRECATED)",
option => configuration.AllowMultipleVersions = option != null)
.Add("x|forcedependencies|force-dependencies|removedependencies|remove-dependencies",
"RemoveDependencies - Uninstall dependencies when uninstalling package(s). Defaults to false.",
option => configuration.ForceDependencies = option != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,6 @@ private void append_output(StringBuilder propertyValues, string append)
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; }
public string DownloadChecksum { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static IConsole Console

public static ChocolateyPackagePathResolver GetPathResolver(ChocolateyConfiguration configuration, IFileSystem nugetPackagesFileSystem)
{
return new ChocolateyPackagePathResolver(ApplicationParameters.PackagesLocation, nugetPackagesFileSystem, configuration.AllowMultipleVersions);
return new ChocolateyPackagePathResolver(ApplicationParameters.PackagesLocation, nugetPackagesFileSystem, useSideBySidePaths: false);
}

public static void ClearRepositoriesCache()
Expand Down
41 changes: 14 additions & 27 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ public virtual ConcurrentDictionary<string, PackageResult> install_run(Chocolate
latestPackageVersion = installedPackage.PackageMetadata.Version;
}

if (installedPackage != null && version != null && version < installedPackage.PackageMetadata.Version && !config.AllowMultipleVersions && !config.AllowDowngrade)
if (installedPackage != null && version != null && version < installedPackage.PackageMetadata.Version && !config.AllowDowngrade)
{
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.Name, 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.".format_with(installedPackage.Name, installedPackage.Version, Environment.NewLine);
var nullResult = packageResultsToReturn.GetOrAdd(packageName, installedPackage);
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
Expand Down Expand Up @@ -707,20 +707,14 @@ Version was specified as '{0}'. It is possible that version
resolvedPackages = dependencyResolver.Resolve(resolverContext, CancellationToken.None)
.Select(p => sourcePackageDependencyInfos.Single(x => PackageIdentityComparer.Default.Equals(x, p)));


if (!config.ForceDependencies)
{
var identitiesToUninstall = packagesToUninstall.Select(x => x.Identity);
resolvedPackages = resolvedPackages.Where(p => !(localPackagesDependencyInfos.Contains(p) && !identitiesToUninstall.Contains(p)));

if (!config.AllowMultipleVersions)
{
// If forcing dependencies, then dependencies already added to packages to remove
// If allow multiple is added, then new version of dependency will be added side by side
// If neither, then package needs to be removed so it can be upgraded to the new version required by the parent

packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase)));
}
// If forcing dependencies, then dependencies already added to packages to remove.
// If not forcing dependencies, then package needs to be removed so it can be upgraded to the new version required by the parent
packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase)));
}
}
catch (NuGetResolverConstraintException ex)
Expand Down Expand Up @@ -1041,9 +1035,9 @@ public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(Chocolate
var pathResolver = NugetCommon.GetPathResolver(config, _fileSystem);
var nugetProject = new FolderNuGetProject(ApplicationParameters.PackagesLocation, pathResolver, NuGetFramework.AnyFramework);

if (version != null && version < installedPackage.PackageMetadata.Version && !config.AllowMultipleVersions && !config.AllowDowngrade)
if (version != null && version < installedPackage.PackageMetadata.Version && !config.AllowDowngrade)
{
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.PackageMetadata.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.".format_with(installedPackage.PackageMetadata.Id, installedPackage.Version, Environment.NewLine);
var nullResult = packageResultsToReturn.GetOrAdd(packageName, new PackageResult(installedPackage.PackageMetadata, pathResolver.GetInstallPath(installedPackage.PackageMetadata.Id, installedPackage.PackageMetadata.Version)));
nullResult.Messages.Add(new ResultMessage(ResultType.Error, logMessage));
this.Log().Error(ChocolateyLoggers.Important, logMessage);
Expand Down Expand Up @@ -1301,14 +1295,9 @@ public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(Chocolate
var identitiesToUninstall = packagesToUninstall.Select(x => x.Identity);
resolvedPackages = resolvedPackages.Where(p => !(localPackagesDependencyInfos.Contains(p) && !identitiesToUninstall.Contains(p)));

if (!config.AllowMultipleVersions)
{
// If forcing dependencies, then dependencies already added to packages to remove
// If allow multiple is added, then new version of dependency will be added side by side
// If neither, then package needs to be removed so it can be upgraded to the new version required by the parent

packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase)));
}
// If forcing dependencies, then dependencies already added to packages to remove.
// If not forcing dependencies, then package needs to be removed so it can be upgraded to the new version required by the parent
packagesToUninstall.AddRange(allLocalPackages.Where(p => resolvedPackages.Select(x => x.Id).Contains(p.Name, StringComparer.OrdinalIgnoreCase)));
}
}
catch (NuGetResolverConstraintException ex)
Expand Down Expand Up @@ -1820,16 +1809,14 @@ protected virtual void ensure_package_files_have_compatible_attributes(Chocolate

[Obsolete("This overload is obsolete and will be removed in a future version.")]
public virtual void rename_legacy_package_version(ChocolateyConfiguration config, IPackageMetadata installedPackage, ChocolateyPackageInformation pkgInfo)
=> normalize_package_legacy_folder_name(config, installedPackage, pkgInfo);
=> normalize_package_legacy_folder_name(config, installedPackage);

protected virtual void normalize_package_legacy_folder_name(ChocolateyConfiguration config, IPackageMetadata installedPackage, ChocolateyPackageInformation pkgInfo)
protected virtual void normalize_package_legacy_folder_name(ChocolateyConfiguration config, IPackageMetadata installedPackage)
{
if (pkgInfo != null && pkgInfo.IsSideBySide) return;

var installDirectory = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, installedPackage.Id);
if (!_fileSystem.directory_exists(installDirectory))
{
// if the folder has a version on it, we need to rename the folder first.
// Legacy resolver mode: if the folder has a version on it, we need to rename the folder first.
var pathResolver = new ChocolateyPackagePathResolver(ApplicationParameters.PackagesLocation, _fileSystem, useSideBySidePaths: true);
installDirectory = pathResolver.GetInstallPath(new PackageIdentity(installedPackage.Id, installedPackage.Version));
if (_fileSystem.directory_exists(installDirectory))
Expand Down Expand Up @@ -2374,7 +2361,7 @@ protected void backup_existing_package_files(ChocolateyConfiguration config, IPa
{
remove_rollback_directory_if_exists(package.Id);
ensure_package_files_have_compatible_attributes(config, package);
normalize_package_legacy_folder_name(config, package, packageInformation);
normalize_package_legacy_folder_name(config, package);
backup_existing_version(config, packageInformation);
remove_shim_directors(config, package);
}
Expand Down

0 comments on commit 9a7b44d

Please sign in to comment.