From 19f068f0d90262d9bbeaf8c53b6dc8ea7215cbb1 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Tue, 29 Aug 2017 17:43:46 -0500 Subject: [PATCH] (GH-1347) API Fix: GetConfiguration() manipulates config Previously, `GetChocoaltey.GetConfiguration()` would allow manipulating the configuration for other calls when using Chocolatey's API. Ensure that it is purely used for informational purposes and won't affect the settings that are used when running Chocolatey's API with future calls. --- src/chocolatey/GetChocolatey.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/chocolatey/GetChocolatey.cs b/src/chocolatey/GetChocolatey.cs index 29a097e95a..c4f0657d46 100644 --- a/src/chocolatey/GetChocolatey.cs +++ b/src/chocolatey/GetChocolatey.cs @@ -331,7 +331,7 @@ public int ListCount() } /// - /// Gets the configuration. Should be used purely for informational purposes + /// Gets a copy of the configuration. Any changes here will have no effect as this is provided purely for informational purposes. /// /// The configuration for Chocolatey /// Only call this once you have registered all container components with Chocolatey @@ -339,7 +339,14 @@ public ChocolateyConfiguration GetConfiguration() { ensure_environment(); - return create_configuration(new List()); + // ensure_original_configuration() already calls create_configuration() + // so no need to repeat, just grab the result + var configuration = ensure_original_configuration( + new List(), + (config) => config + ); + + return configuration; } private void ensure_original_configuration(IList args, Action action)