From 0e10a51802cd4e1e2d3afa3d96d0d0daff200ecf Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 6 Jun 2016 13:37:27 -0700 Subject: [PATCH] Whitespace and formatting cleanups --- .../Cmdlets.cs | 35 ++++---- .../CoreCLR/CorePsPlatform.cs | 90 +++++++++---------- .../engine/Modules/ModuleIntrinsics.cs | 1 - .../engine/Utils.cs | 2 +- .../engine/hostifaces/HostUtilities.cs | 3 - 5 files changed, 63 insertions(+), 68 deletions(-) diff --git a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs index ffb40e744..8c2f37004 100644 --- a/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs +++ b/src/Microsoft.PowerShell.PSReadLine/Cmdlets.cs @@ -169,40 +169,39 @@ namespace Microsoft.PowerShell WordDelimiters = DefaultWordDelimiters; HistorySearchCaseSensitive = DefaultHistorySearchCaseSensitive; HistorySaveStyle = DefaultHistorySaveStyle; + + string historyFileName = hostName + "_history.txt"; #if CORECLR if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) // MS Windows { HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("APPDATA"), @"Microsoft\Windows\PowerShell\PSReadline\", - hostName + "_history.txt"); + historyFileName); } - else { - //PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path seperately - string historypath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); - - if (!String.IsNullOrEmpty(historypath)) - { - historypath = System.IO.Path.Combine(historypath, "powershell", "PSReadLine", hostName + "_history.txt"); - HistorySavePath = historypath; - } + // PSReadline does not have access to Utils.CorePSPlatform. Must set PSReadline path separately + string historyPath = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME"); + if (!String.IsNullOrEmpty(historyPath)) + { + historyPath = System.IO.Path.Combine(historyPath, "powershell", "PSReadLine", historyFileName); + HistorySavePath = historyPath; + } else { - //While a module, history save path goes into the larger .local/share/powershell folder - HistorySavePath = System.IO.Path.Combine( - Environment.GetEnvironmentVariable("HOME"), + // History is data, so it goes into .local/share/powershell folder + HistorySavePath = System.IO.Path.Combine(Environment.GetEnvironmentVariable("HOME"), ".local", "share", - "powershell", + "powershell", "PSReadLine", - hostName + "_history.txt"); + historyFileName); } } #else - HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) - + @"\Microsoft\Windows\PowerShell\PSReadline\" + hostName + "_history.txt"; + HistorySavePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + + @"\Microsoft\Windows\PowerShell\PSReadline\" + historyFileName; #endif CommandValidationHandler = null; CommandsToValidateScriptBlockArguments = new HashSet(StringComparer.OrdinalIgnoreCase) @@ -221,7 +220,7 @@ namespace Microsoft.PowerShell "Where-Object", "?", "where", }; } - + public EditMode EditMode { get; set; } public string ContinuationPrompt { get; set; } diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index b7748cd97..1110b2623 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -21,6 +21,7 @@ using SpecialFolder = System.Management.Automation.Environment.SpecialFolder; namespace System.Management.Automation { + /// /// These are platform abstractions and platform specific implementations /// @@ -42,15 +43,14 @@ namespace System.Management.Automation #endif } } - + //enum for selecting the xdgpaths public enum XDG_Type { PROFILE, MODULES, - CACHE, + CACHE, DEFAULT - } public static bool IsOSX @@ -105,7 +105,7 @@ namespace System.Management.Automation "WSMan.format.ps1xml" }; - // function for choosing directory location of PowerShell for profile loading + // function for choosing directory location of PowerShell for profile loading public static string SelectProductNameForDirectory (Platform.XDG_Type dirpath) { @@ -116,49 +116,49 @@ namespace System.Management.Automation string xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME"); string xdgConfigHomeDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".config", "powershell"); string xdgModuleDefault = Path.Combine ( System.Environment.GetEnvironmentVariable("HOME"), ".local", "share", "powershell", "Modules"); - string xdgCacheDefault = Path.Combine (System.Environment.GetEnvironmentVariable("HOME"), ".cache", "powershell"); - + string xdgCacheDefault = Path.Combine (System.Environment.GetEnvironmentVariable("HOME"), ".cache", "powershell"); + switch (dirpath){ - case Platform.XDG_Type.PROFILE: + case Platform.XDG_Type.PROFILE: //the user has set XDG_CONFIG_HOME corrresponding to profile path if (String.IsNullOrEmpty(xdgconfighome)) { //xdg values have not been set - return xdgConfigHomeDefault; + return xdgConfigHomeDefault; } else { - return Path.Combine(xdgconfighome, "powershell"); + return Path.Combine(xdgconfighome, "powershell"); } - - case Platform.XDG_Type.MODULES: - //the user has set XDG_DATA_HOME corresponding to module path + + case Platform.XDG_Type.MODULES: + //the user has set XDG_DATA_HOME corresponding to module path if (String.IsNullOrEmpty(xdgdatahome)){ - - //xdg values have not been set + + //xdg values have not been set if (!Directory.Exists(xdgModuleDefault)) //module folder not always guaranteed to exist - { - Directory.CreateDirectory(xdgModuleDefault); + { + Directory.CreateDirectory(xdgModuleDefault); } - return xdgModuleDefault; + return xdgModuleDefault; } else { - return Path.Combine(xdgdatahome, "powershell", "Modules"); - } - + return Path.Combine(xdgdatahome, "powershell", "Modules"); + } + case Platform.XDG_Type.CACHE: //the user has set XDG_CACHE_HOME if (String.IsNullOrEmpty(xdgcachehome)) { - //xdg values have not been set + //xdg values have not been set if (!Directory.Exists(xdgCacheDefault)) //module folder not always guaranteed to exist - { - Directory.CreateDirectory(xdgCacheDefault); + { + Directory.CreateDirectory(xdgCacheDefault); } - - return xdgCacheDefault; + + return xdgCacheDefault; } else @@ -168,30 +168,30 @@ namespace System.Management.Automation Directory.CreateDirectory(Path.Combine(xdgcachehome, "powershell")); } - return Path.Combine(xdgcachehome, "powershell"); - } - - case Platform.XDG_Type.DEFAULT: + return Path.Combine(xdgcachehome, "powershell"); + } + + case Platform.XDG_Type.DEFAULT: //default for profile location return xdgConfigHomeDefault; - default: + default: //xdgConfigHomeDefault needs to be created in the edge case that we do not have the folder or it was deleted //This folder is the default in the event of all other failures for data storage - if (!Directory.Exists(xdgConfigHomeDefault)) - { - try { + if (!Directory.Exists(xdgConfigHomeDefault)) + { + try { Directory.CreateDirectory(xdgConfigHomeDefault); - } + } catch{ - + Console.Error.WriteLine("Failed to create default data directory: " + xdgConfigHomeDefault); - } + } } - - return xdgConfigHomeDefault; + + return xdgConfigHomeDefault; } - + } // ComObjectType is null on CoreCLR for Linux since there is @@ -458,7 +458,7 @@ namespace System.Management.Automation throw new InvalidOperationException("LinuxPlatform.NonWindowsHostName error: " + lastError); } return hostName; - + } else { @@ -481,7 +481,7 @@ namespace System.Management.Automation // TODO:PSL clean this up return 0; } - + /// /// This exception is meant to be thrown if a code path is not supported due /// to platform restrictions @@ -665,7 +665,7 @@ namespace System.Management.Automation int ret = Native.IsSymLink(filePath); switch(ret) { - case 1: + case 1: return true; case 0: return false; @@ -685,7 +685,7 @@ namespace System.Management.Automation int ret = Native.IsExecutable(filePath); switch(ret) { - case 1: + case 1: return true; case 0: return false; @@ -780,11 +780,11 @@ namespace System.Management.Automation internal static extern int SetDate(SetDateInfoInternal info); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath, + internal static extern int CreateSymLink([MarshalAs(UnmanagedType.LPStr)]string filePath, [MarshalAs(UnmanagedType.LPStr)]string target); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string filePath, + internal static extern int CreateHardLink([MarshalAs(UnmanagedType.LPStr)]string filePath, [MarshalAs(UnmanagedType.LPStr)]string target); [DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)] diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index 12a9c81f7..66f9e5ede 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -604,7 +604,6 @@ namespace System.Management.Automation psHome = psHome.ToLowerInvariant().Replace("\\syswow64\\", "\\system32\\"); } Interlocked.CompareExchange(ref SystemWideModulePath, Path.Combine(psHome, Utils.ModuleDirectory), null); - } return SystemWideModulePath; diff --git a/src/System.Management.Automation/engine/Utils.cs b/src/System.Management.Automation/engine/Utils.cs index d499f3ad3..ac23e8014 100644 --- a/src/System.Management.Automation/engine/Utils.cs +++ b/src/System.Management.Automation/engine/Utils.cs @@ -612,7 +612,7 @@ namespace System.Management.Automation /// The name of the subdirectory that contains packages. /// internal static string ModuleDirectory = "Modules"; - + /// /// The partial path to the DSC module directory /// diff --git a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs index 592c0dcae..32d415965 100644 --- a/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs +++ b/src/System.Management.Automation/engine/hostifaces/HostUtilities.cs @@ -152,7 +152,6 @@ namespace System.Management.Automation { continue; } - command = new PSCommand(); command.AddCommand(profilePath, false); commands.Add(command); @@ -187,9 +186,7 @@ namespace System.Management.Automation { basePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); basePath = IO.Path.Combine(basePath, Utils.ProductNameForDirectory); - } - else { basePath = GetAllUsersFolderPath(shellId);