Skip to content

Commit

Permalink
(GH-1210) CacheLocation - Prevent nested chocolatey directories
Browse files Browse the repository at this point in the history
This ensures that the CacheLocation only appends chocolatey to the TEMP variable
if it has not already been added. Otherwise multiple package installs in the
same process result in an ever deeper nested chocolatey cache folders, resulting
in eventual `PATH too long` errors. This appears to affect only API usage of
Chocolatey.
  • Loading branch information
mwrock authored and ferventcoder committed Mar 28, 2017
1 parent 8dc774e commit 39b04f9
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,16 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi
private static void set_config_items(ChocolateyConfiguration config, ConfigFileSettings configFileSettings, IFileSystem fileSystem)
{
config.CacheLocation = Environment.ExpandEnvironmentVariables(set_config_item(ApplicationParameters.ConfigSettings.CacheLocation, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? string.Empty : configFileSettings.CacheLocation, "Cache location if not TEMP folder."));
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.combine_paths(fileSystem.get_temp_path(), "chocolatey"); // System.Environment.GetEnvironmentVariable("TEMP");
if (string.IsNullOrWhiteSpace(config.CacheLocation)) {
config.CacheLocation = fileSystem.get_temp_path(); // System.Environment.GetEnvironmentVariable("TEMP");
// TEMP gets set in EnvironmentSettings, so it may already have
// chocolatey in the path when it installs the next package from
// the API.
if(!config.CacheLocation.EndsWith("chocolatey")) {
config.CacheLocation = fileSystem.combine_paths(fileSystem.get_temp_path(), "chocolatey");
}
}

// if it is still empty, use temp in the Chocolatey install directory.
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");

Expand Down

0 comments on commit 39b04f9

Please sign in to comment.