Skip to content

Commit

Permalink
(chocolateyGH-1040) use lower case for uninstall / log more
Browse files Browse the repository at this point in the history
When uninstalling packages, attempt to use lower case as the local file
system could be having issues finding the package. Log more surrounding
what is going on to try to pinpoint the source of the issue. Also skip
removing files if they are already deleted.
  • Loading branch information
ferventcoder committed Sep 7, 2017
1 parent d677e5d commit d56d8ed
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -1326,7 +1329,7 @@ public ConcurrentDictionary<string, PackageResult> 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);
Expand Down Expand Up @@ -1366,12 +1369,15 @@ public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfi
/// <param name="pkgInfo">The package information.</param>
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",
Expand All @@ -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));

Expand All @@ -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");
Expand Down

0 comments on commit d56d8ed

Please sign in to comment.