Skip to content

Commit

Permalink
(GH-622) Remove NuGet temp folders
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
ferventcoder committed May 27, 2016
1 parent 0a8baca commit a3ef04d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/chocolatey/infrastructure.app/runners/GenericRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

/// <summary>
/// if there is a NuGetScratch cache found, kill it with fire
/// </summary>
/// <param name="container">The container.</param>
private void remove_nuget_cache(Container container)
{
try
{
var fileSystem = container.GetInstance<IFileSystem>();
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<T> list<T>(ChocolateyConfiguration config, Container container, bool isConsole, Action<ICommand> parseArgs)
Expand Down

0 comments on commit a3ef04d

Please sign in to comment.