diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index a5aae98f3f..1262cb1689 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1061,8 +1061,11 @@ private void remove_shim_directors(ChocolateyConfiguration config, IPackage inst private void remove_cache_for_package(ChocolateyConfiguration config, IPackage installedPackage) { + this.Log().Debug(ChocolateyLoggers.Verbose, "Ensuring removal of package cache files."); var cacheDirectory = _fileSystem.combine_paths(config.CacheLocation, installedPackage.Id, installedPackage.Version.to_string()); + if (!_fileSystem.directory_exists(cacheDirectory)) return; + FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.delete_directory_if_exists(cacheDirectory, recursive: true), "Unable to removed cached files"); @@ -1326,7 +1329,7 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi 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); + packageManager.UninstallPackage(packageVersion.Id.to_lower(), forceRemove: config.Force, removeDependencies: config.ForceDependencies, version: packageVersion.Version); ensure_nupkg_is_removed(packageVersion, pkgInfo); remove_installation_files(packageVersion, pkgInfo); remove_cache_for_package(config, packageVersion); @@ -1366,12 +1369,15 @@ public ConcurrentDictionary uninstall_run(ChocolateyConfi /// The package information. private void ensure_nupkg_is_removed(IPackage removedPackage, ChocolateyPackageInformation pkgInfo) { + this.Log().Debug(ChocolateyLoggers.Verbose, "Removing nupkg if it still exists."); var isSideBySide = pkgInfo != null && pkgInfo.IsSideBySide; var nupkgFile = "{0}{1}.nupkg".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty); var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, "{0}{1}".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty)); var nupkg = _fileSystem.combine_paths(installDir, nupkgFile); + if (!_fileSystem.file_exists(nupkg)) return; + FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.delete_file(nupkg), "Error deleting nupkg file", @@ -1380,6 +1386,7 @@ private void ensure_nupkg_is_removed(IPackage removedPackage, ChocolateyPackageI public void remove_installation_files(IPackage removedPackage, ChocolateyPackageInformation pkgInfo) { + this.Log().Debug(ChocolateyLoggers.Verbose, "Ensuring removal of installation files."); var isSideBySide = pkgInfo != null && pkgInfo.IsSideBySide; var installDir = _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, "{0}{1}".format_with(removedPackage.Id, isSideBySide ? "." + removedPackage.Version.to_string() : string.Empty)); @@ -1392,6 +1399,8 @@ public void remove_installation_files(IPackage removedPackage, ChocolateyPackage if (fileSnapshot.Checksum == _filesService.get_package_file(file).Checksum) { + if (!_fileSystem.file_exists(file)) continue; + FaultTolerance.try_catch_with_logging_exception( () => _fileSystem.delete_file(file), "Error deleting file");