public ConcurrentDictionary <string, PackageResult> uninstall_run(ChocolateyConfiguration config) { this.Log().Info(@"Uninstalling the following packages:"); this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); var packageUninstalls = _nugetService.uninstall_run( config, (packageResult) => { if (!_fileSystem.directory_exists(packageResult.InstallLocation)) { packageResult.InstallLocation += ".{0}".format_with(packageResult.Package.Version.to_string()); } _shimgenService.uninstall(config, packageResult); if (!config.SkipPackageInstallProvider) { _powershellService.uninstall(config, packageResult); } _autoUninstallerService.run(packageResult, config); if (packageResult.Success) { //todo: v2 clean up package information store for things no longer installed (call it compact?) _packageInfoService.remove_package_information(packageResult.Package); } //todo:prevent reboots }); var uninstallFailures = packageUninstalls.Count(p => !p.Value.Success); this.Log().Warn(() => @"{0}{1} uninstalled {2}/{3} packages. {4} packages failed.{0}See the log for details.".format_with( Environment.NewLine, ApplicationParameters.Name, packageUninstalls.Count(p => p.Value.Success && !p.Value.Inconclusive), packageUninstalls.Count, uninstallFailures)); if (uninstallFailures != 0) { this.Log().Error("Failures"); foreach (var failure in packageUninstalls.Where(p => !p.Value.Success).or_empty_list_if_null()) { this.Log().Error(" - {0}".format_with(failure.Value.Name)); } } if (uninstallFailures != 0 && Environment.ExitCode == 0) { Environment.ExitCode = 1; } return(packageUninstalls); }
public void handle_package_uninstall(PackageResult packageResult, ChocolateyConfiguration config) { if (!_fileSystem.directory_exists(packageResult.InstallLocation)) { packageResult.InstallLocation += ".{0}".format_with(packageResult.Package.Version.to_string()); } _shimgenService.uninstall(config, packageResult); if (!config.SkipPackageInstallProvider) { _powershellService.uninstall(config, packageResult); } if (packageResult.Success) { _autoUninstallerService.run(packageResult, config); } // we don't care about the exit code if (config.Information.PlatformType == PlatformType.Windows) { CommandExecutor.execute_static("shutdown", "/a", config.CommandExecutionTimeoutSeconds, _fileSystem.get_current_directory(), (s, e) => { }, (s, e) => { }, false); } if (packageResult.Success) { //todo: v2 clean up package information store for things no longer installed (call it compact?) uninstall_cleanup(config, packageResult); } else { this.Log().Error(ChocolateyLoggers.Important, "{0} {1} not successful.".format_with(packageResult.Name, "uninstall")); handle_unsuccessful_operation(config, packageResult, movePackageToFailureLocation: false, attemptRollback: false); } if (!packageResult.Success) { // throw an error so that NuGet Service doesn't attempt to continue with package removal throw new ApplicationException("{0} {1} not successful.".format_with(packageResult.Name, "uninstall")); } }
public ConcurrentDictionary <string, PackageResult> uninstall_run(ChocolateyConfiguration config) { this.Log().Info(@"Uninstalling the following packages:"); this.Log().Info(ChocolateyLoggers.Important, @"{0}".format_with(config.PackageNames)); foreach (var packageConfigFile in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null().Where(p => p.EndsWith(".config")).ToList()) { throw new ApplicationException("A packages.config file is only used with installs."); } var packageUninstalls = _nugetService.uninstall_run( config, (packageResult) => { if (!_fileSystem.directory_exists(packageResult.InstallLocation)) { packageResult.InstallLocation += ".{0}".format_with(packageResult.Package.Version.to_string()); } _shimgenService.uninstall(config, packageResult); if (!config.SkipPackageInstallProvider) { _powershellService.uninstall(config, packageResult); } _autoUninstallerService.run(packageResult, config); if (packageResult.Success) { //todo: v2 clean up package information store for things no longer installed (call it compact?) uninstall_cleanup(config, packageResult); } else { this.Log().Error(ChocolateyLoggers.Important, "{0} {1} not successful.".format_with(packageResult.Name, "uninstall")); handle_unsuccessful_operation(config, packageResult, movePackageToFailureLocation: false, attemptRollback: false); } //todo:prevent reboots }); var uninstallFailures = packageUninstalls.Count(p => !p.Value.Success); this.Log().Warn(() => @"{0}{1} uninstalled {2}/{3} packages. {4} packages failed.{0} See the log for details ({5}).".format_with( Environment.NewLine, ApplicationParameters.Name, packageUninstalls.Count(p => p.Value.Success && !p.Value.Inconclusive), packageUninstalls.Count, uninstallFailures, _fileSystem.combine_paths(ApplicationParameters.LoggingLocation, ApplicationParameters.LoggingFile) )); if (uninstallFailures != 0) { this.Log().Error("Failures"); foreach (var failure in packageUninstalls.Where(p => !p.Value.Success).or_empty_list_if_null()) { this.Log().Error(" - {0}".format_with(failure.Value.Name)); } } if (uninstallFailures != 0 && Environment.ExitCode == 0) { Environment.ExitCode = 1; } return(packageUninstalls); }