From ca307e7c95985ebd55a844ae8304c036b361b223 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Mon, 8 Aug 2016 21:05:48 -0700 Subject: [PATCH 1/5] Fixing JsonConfigFileAccessor constructor so that it doesn't throw exceptions when run as a regular user. --- .../engine/PropertyAccessor.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/System.Management.Automation/engine/PropertyAccessor.cs b/src/System.Management.Automation/engine/PropertyAccessor.cs index 6a63302ad..02e67aa79 100644 --- a/src/System.Management.Automation/engine/PropertyAccessor.cs +++ b/src/System.Management.Automation/engine/PropertyAccessor.cs @@ -147,25 +147,15 @@ namespace System.Management.Automation internal JsonConfigFileAccessor() { // - // Initialize (and create if necessary) the system-wide configuration directory + // Sets the system-wide configuration directory // Assembly assembly = typeof(PSObject).GetTypeInfo().Assembly; - psHomeConfigDirectory = Path.Combine(Path.GetDirectoryName(assembly.Location), configDirectoryName); - - if (!Directory.Exists(psHomeConfigDirectory)) - { - Directory.CreateDirectory(psHomeConfigDirectory); - } + psHomeConfigDirectory = Path.GetDirectoryName(assembly.Location); // - // Initialize (and create if necessary) the per-user configuration directory + // Sets the per-user configuration directory // - appDataConfigDirectory = Path.Combine(Utils.GetUserSettingsDirectory(), configDirectoryName); - - if (!Directory.Exists(appDataConfigDirectory)) - { - Directory.CreateDirectory(appDataConfigDirectory); - } + appDataConfigDirectory = Utils.GetUserSettingsDirectory(); } /// From 06c4d7e01fa7001d455380939977e477e01d4334 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 9 Aug 2016 13:57:33 -0700 Subject: [PATCH 2/5] Trying an idea to see if this will display the AppVeyor error since I cannot reproduce it locally. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 6caea8428..e0807a543 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,7 +34,7 @@ build_script: test_script: - ps: | # fail tests execution, if any PS error detected - $ErrorActionPreference = 'Stop' + $ErrorActionPreference = 'Continue' # # CoreCLR $env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish)) From 063fd9c8f6ac204eae2d48bbfbce2244c2a4b1da Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 9 Aug 2016 14:46:22 -0700 Subject: [PATCH 3/5] Removing directory creation from initialization. --- .../engine/PropertyAccessor.cs | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/engine/PropertyAccessor.cs b/src/System.Management.Automation/engine/PropertyAccessor.cs index 02e67aa79..076e4b485 100644 --- a/src/System.Management.Automation/engine/PropertyAccessor.cs +++ b/src/System.Management.Automation/engine/PropertyAccessor.cs @@ -134,7 +134,6 @@ namespace System.Management.Automation { private string psHomeConfigDirectory; private string appDataConfigDirectory; - private const string configDirectoryName = "Configuration"; private const string configFileName = "PowerShellProperties.json"; /// @@ -156,6 +155,38 @@ namespace System.Management.Automation // Sets the per-user configuration directory // appDataConfigDirectory = Utils.GetUserSettingsDirectory(); + if (!Directory.Exists(appDataConfigDirectory)) + { + try + { + Directory.CreateDirectory(appDataConfigDirectory); + } + catch (UnauthorizedAccessException) + { + // Do nothing now. This failure shouldn't block initialization + appDataConfigDirectory = null; + } + } + } + + /// + /// Enables delayed creation of the user settings directory so it does not interfere with PowerShell initialization + /// + /// Returns the directory if present or creatable. Throws otherwise. + private string GetAppDataConfigDirectory() + { + if (null == appDataConfigDirectory) + { + string tempAppDataConfigDir = Utils.GetUserSettingsDirectory(); + if (!Directory.Exists(tempAppDataConfigDir)) + { + Directory.CreateDirectory(tempAppDataConfigDir); + // Only assign it if creation succeeds. It will throw if it fails. + appDataConfigDirectory = tempAppDataConfigDir; + } + // Do not catch exceptions here. Let them flow up. + } + return appDataConfigDirectory; } /// @@ -170,7 +201,7 @@ namespace System.Management.Automation // Defaults to system wide. if (PropertyScope.CurrentUser == scope) { - scopeDirectory = appDataConfigDirectory; + scopeDirectory = GetAppDataConfigDirectory(); } string fileName = Path.Combine(scopeDirectory, configFileName); @@ -205,7 +236,7 @@ namespace System.Management.Automation // Defaults to system wide. if(PropertyScope.CurrentUser == scope) { - scopeDirectory = appDataConfigDirectory; + scopeDirectory = GetAppDataConfigDirectory(); } string fileName = Path.Combine(scopeDirectory, configFileName); @@ -226,7 +257,7 @@ namespace System.Management.Automation // Defaults to system wide. if (PropertyScope.CurrentUser == scope) { - scopeDirectory = appDataConfigDirectory; + scopeDirectory = GetAppDataConfigDirectory(); } string fileName = Path.Combine(scopeDirectory, configFileName); @@ -241,7 +272,7 @@ namespace System.Management.Automation // Defaults to system wide. if (PropertyScope.CurrentUser == scope) { - scopeDirectory = appDataConfigDirectory; + scopeDirectory = GetAppDataConfigDirectory(); } string fileName = Path.Combine(scopeDirectory, configFileName); From fd489544dfa37fb733269213ead925f85140687d Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 9 Aug 2016 15:27:39 -0700 Subject: [PATCH 4/5] Revert "Trying an idea to see if this will display the AppVeyor error since I cannot reproduce it locally." This reverts commit 06c4d7e01fa7001d455380939977e477e01d4334 to undo an appveyor expiriment. --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index e0807a543..6caea8428 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,7 +34,7 @@ build_script: test_script: - ps: | # fail tests execution, if any PS error detected - $ErrorActionPreference = 'Continue' + $ErrorActionPreference = 'Stop' # # CoreCLR $env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish)) From 6575500b7939d4207fb57d7cc9a8e405c029dc13 Mon Sep 17 00:00:00 2001 From: Mike Richmond Date: Tue, 9 Aug 2016 16:31:26 -0700 Subject: [PATCH 5/5] Whitespace change to retrigger a build --- src/System.Management.Automation/engine/PropertyAccessor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/PropertyAccessor.cs b/src/System.Management.Automation/engine/PropertyAccessor.cs index 076e4b485..15203fa24 100644 --- a/src/System.Management.Automation/engine/PropertyAccessor.cs +++ b/src/System.Management.Automation/engine/PropertyAccessor.cs @@ -170,7 +170,8 @@ namespace System.Management.Automation } /// - /// Enables delayed creation of the user settings directory so it does not interfere with PowerShell initialization + /// Enables delayed creation of the user settings directory so it does + /// not interfere with PowerShell initialization /// /// Returns the directory if present or creatable. Throws otherwise. private string GetAppDataConfigDirectory()