Skip to content

Commit

Permalink
(GH-479) Remove NuGet cache of package
Browse files Browse the repository at this point in the history
Chocolatey doesn't use the NuGet cache at all, but NuGet always caches
the package in the NuGet cache (and there is not a way to shut it off
with NuGet calls unfortunately). This can cause issues when later using
NuGet and trying to install a package from NuGet.org that is different,
but carries the same name. The cached file will be served to the user
causing hard to detect issues. Therefore we need to clean up after
NuGet as there is no way to tell it NOT to cache the nupkg during
install/upgrade.
  • Loading branch information
ferventcoder committed Jan 30, 2016
1 parent 3757e7d commit f48b490
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfigu
{
packageManager.InstallPackage(availablePackage, ignoreDependencies: config.IgnoreDependencies, allowPrereleaseVersions: config.Prerelease);
//packageManager.InstallPackage(packageName, version, configuration.IgnoreDependencies, configuration.Prerelease);
remove_nuget_cache_for_package(availablePackage);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -721,6 +722,7 @@ public ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfigu
{
packageManager.UpdatePackage(availablePackage, updateDependencies: !config.IgnoreDependencies, allowPrereleaseVersions: config.Prerelease);
}
remove_nuget_cache_for_package(availablePackage);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -911,6 +913,25 @@ private void remove_cache_for_package( ChocolateyConfiguration config, IPackage
"Unable to removed cached files");
}

/// <summary>
/// Remove NuGet cache of the package.
/// Whether we use the cached file or not, NuGet always caches the package.
/// This is annoying with choco, but if you use both choco and NuGet, it can
/// cause hard to detect issues in NuGet when there is a NuGet package of the
/// same name with different contents.
/// </summary>
/// <param name="installedPackage">The installed package.</param>
private void remove_nuget_cache_for_package(IPackage installedPackage)
{
var nugetCachedFile = _fileSystem.combine_paths(Environment.GetEnvironmentVariable("LocalAppData"), "NuGet", "Cache", "{0}.{1}.nupkg".format_with(installedPackage.Id, installedPackage.Version.to_string()));
if (_fileSystem.file_exists(nugetCachedFile))
{
FaultTolerance.try_catch_with_logging_exception(
() => _fileSystem.delete_file(nugetCachedFile),
"Unable to removed cached NuGet package file");
}
}

public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
var results = uninstall_run(config, continueAction, performAction: false);
Expand Down

0 comments on commit f48b490

Please sign in to comment.