From a3ef04d1f7f2b8f5681a76f11086321a4a625d0b Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Fri, 27 May 2016 08:33:34 -0500 Subject: [PATCH] (GH-622) Remove NuGet temp folders `TEMP\NuGetScratch` and sometimes a `TEMP\x\Nuget` folder are created by NuGet Core, however it doesn't clean up after itself on this. It is expected for you to call `OptimizedZipPackage.PurgeCache()`, but this does not appear to actually remove the folder because PurgeCache is dependent on the GUID that it creates for the subdirectory. It doesn't hold a reference to that and so it comes up with one that doesn't exist by the time we call it. Handle cleaning up those caches at the end of most runs. --- .../runners/GenericRunner.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs index d6853a53df..7a0d9c84f4 100644 --- a/src/chocolatey/infrastructure.app/runners/GenericRunner.cs +++ b/src/chocolatey/infrastructure.app/runners/GenericRunner.cs @@ -19,6 +19,7 @@ namespace chocolatey.infrastructure.app.runners using System; using System.Linq; using System.Collections.Generic; + using filesystem; using SimpleInjector; using adapters; using attributes; @@ -139,6 +140,28 @@ public void run(ChocolateyConfiguration config, Container container, bool isCons this.Log().Debug("_ {0}:{1} - Normal Run Mode _".format_with(ApplicationParameters.Name, command.GetType().Name)); command.run(config); } + + remove_nuget_cache(container); + } + + /// + /// if there is a NuGetScratch cache found, kill it with fire + /// + /// The container. + private void remove_nuget_cache(Container container) + { + try + { + var fileSystem = container.GetInstance(); + var scratch = fileSystem.combine_paths(fileSystem.get_temp_path(), "NuGetScratch"); + fileSystem.delete_directory_if_exists(scratch, recursive: true, overrideAttributes: true, isSilent: true); + var nugetX = fileSystem.combine_paths(fileSystem.get_temp_path(), "x", "nuget"); + fileSystem.delete_directory_if_exists(nugetX, recursive: true, overrideAttributes: true, isSilent: true); + } + catch (Exception ex) + { + this.Log().Debug(ChocolateyLoggers.Important, "Not able to cleanup NuGet temp folders. Failure was {0}".format_with(ex.Message)); + } } public IEnumerable list(ChocolateyConfiguration config, Container container, bool isConsole, Action parseArgs)