diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index d8999d2795..31f7e88c79 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -745,8 +745,8 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi } var environmentBefore = get_environment_before(config); - - var packageUninstalls = perform_source_runner_function(config, r => r.uninstall_run(config, action)); + var beforeUninstallAction = new Action(packageResult => before_package_modify(packageResult, config)); + var packageUninstalls = perform_source_runner_function(config, r => r.uninstall_run(config, action, beforeUninstallAction)); // not handled in the uninstall handler IEnumerable environmentChanges; @@ -862,11 +862,6 @@ public void handle_package_uninstall(PackageResult packageResult, ChocolateyConf packageResult.InstallLocation += ".{0}".format_with(packageResult.Package.Version.to_string()); } - if (!config.SkipPackageInstallProvider) - { - _powershellService.before_modify(config, packageResult); - } - _shimgenService.uninstall(config, packageResult); if (!config.SkipPackageInstallProvider) diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 34992ebfd7..67a450260b 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -389,9 +389,6 @@ public ConcurrentDictionary install_run(ChocolateyConfigu foreach (string packageName in packageNames.or_empty_list_if_null()) { //todo: get smarter about realizing multiple versions have been installed before and allowing that - - remove_rollback_directory_if_exists(packageName); - IPackage installedPackage = packageManager.LocalRepository.FindPackage(packageName); if (installedPackage != null && (version == null || version == installedPackage.Version) && !config.Force) @@ -433,7 +430,8 @@ public ConcurrentDictionary install_run(ChocolateyConfigu { var forcedResult = packageInstalls.GetOrAdd(packageName, new PackageResult(availablePackage, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, availablePackage.Id))); forcedResult.Messages.Add(new ResultMessage(ResultType.Note, "Backing up and removing old version")); - + + remove_rollback_directory_if_exists(packageName); backup_existing_version(config, installedPackage, _packageInfoService.get_package_information(installedPackage)); try @@ -543,8 +541,6 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu foreach (string packageName in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null()) { - remove_rollback_directory_if_exists(packageName); - IPackage installedPackage = packageManager.LocalRepository.FindPackage(packageName); if (installedPackage == null) @@ -717,14 +713,15 @@ public ConcurrentDictionary upgrade_run(ChocolateyConfigu packageName, version == null ? null : version.ToString())) { - ensure_package_files_have_compatible_attributes(config, installedPackage, pkgInfo); - rename_legacy_package_version(config, installedPackage, pkgInfo); if (beforeUpgradeAction != null) { var currentPackageResult = new PackageResult(installedPackage, get_install_directory(config, installedPackage)); beforeUpgradeAction(currentPackageResult); } + remove_rollback_directory_if_exists(packageName); + ensure_package_files_have_compatible_attributes(config, installedPackage, pkgInfo); + rename_legacy_package_version(config, installedPackage, pkgInfo); backup_existing_version(config, installedPackage, pkgInfo); remove_shim_directors(config, installedPackage, pkgInfo); if (config.Force && (installedPackage.Version == availablePackage.Version)) @@ -1089,8 +1086,6 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi foreach (string packageName in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null()) { - remove_rollback_directory_if_exists(packageName); - IList installedPackageVersions = new List(); if (string.IsNullOrWhiteSpace(config.Version)) { @@ -1177,8 +1172,16 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi packageVersion.Id, packageVersion.Version.to_string()) ) { + if (beforeUninstallAction != null) + { + // guessing this is not added so that it doesn't fail the action if an error is recorded? + //var currentPackageResult = packageUninstalls.GetOrAdd(packageName, new PackageResult(packageVersion, get_install_directory(config, packageVersion))); + var currentPackageResult = new PackageResult(packageVersion, get_install_directory(config, packageVersion)); + beforeUninstallAction(currentPackageResult); + } ensure_package_files_have_compatible_attributes(config, packageVersion, pkgInfo); rename_legacy_package_version(config, packageVersion, pkgInfo); + remove_rollback_directory_if_exists(packageName); backup_existing_version(config, packageVersion, pkgInfo); packageManager.UninstallPackage(packageVersion.Id, forceRemove: config.Force, removeDependencies: config.ForceDependencies, version: packageVersion.Version); ensure_nupkg_is_removed(packageVersion, pkgInfo);