diff --git a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs index c6d775f63d..57964c2fed 100644 --- a/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs +++ b/src/System.Management.Automation/CoreCLR/CorePsPlatform.cs @@ -203,10 +203,11 @@ namespace System.Management.Automation #endif } +#if UNIX /// /// X Desktop Group configuration type enum. /// - public enum XDG_Type + internal enum XDG_Type { /// XDG_CONFIG_HOME/powershell CONFIG, @@ -215,7 +216,9 @@ namespace System.Management.Automation /// XDG_DATA_HOME/powershell DATA, /// XDG_DATA_HOME/powershell/Modules - MODULES, + USER_MODULES, + /// /usr/local/share/powershell/Modules + SHARED_MODULES, /// XDG_CONFIG_HOME/powershell DEFAULT } @@ -223,7 +226,7 @@ namespace System.Management.Automation /// /// function for choosing directory location of PowerShell for profile loading /// - public static string SelectProductNameForDirectory(Platform.XDG_Type dirpath) + internal static string SelectProductNameForDirectory(Platform.XDG_Type dirpath) { //TODO: XDG_DATA_DIRS implementation as per GitHub issue #1060 @@ -266,7 +269,7 @@ namespace System.Management.Automation return Path.Combine(xdgdatahome, "powershell"); } - case Platform.XDG_Type.MODULES: + case Platform.XDG_Type.USER_MODULES: //the user has set XDG_DATA_HOME corresponding to module path if (String.IsNullOrEmpty(xdgdatahome)) { @@ -282,6 +285,9 @@ namespace System.Management.Automation return Path.Combine(xdgdatahome, "powershell", "Modules"); } + case Platform.XDG_Type.SHARED_MODULES: + return "/usr/local/share/powershell/Modules"; + case Platform.XDG_Type.CACHE: //the user has set XDG_CACHE_HOME if (String.IsNullOrEmpty(xdgcachehome)) @@ -327,6 +333,7 @@ namespace System.Management.Automation return xdgConfigHomeDefault; } } +#endif // Platform methods prefixed NonWindows are: // - non-windows by the definition of the IsWindows method above diff --git a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs index ea441ed2af..52bc75e35f 100644 --- a/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs +++ b/src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs @@ -535,7 +535,7 @@ namespace System.Management.Automation internal static string GetPersonalModulePath() { #if UNIX - return Platform.SelectProductNameForDirectory(Platform.XDG_Type.MODULES); + return Platform.SelectProductNameForDirectory(Platform.XDG_Type.USER_MODULES); #else return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), Utils.ModuleDirectory); #endif @@ -582,7 +582,7 @@ namespace System.Management.Automation internal static string GetDscModulePath() { #if UNIX - return string.Empty; + return Platform.SelectProductNameForDirectory(Platform.XDG_Type.SHARED_MODULES); #else string dscModulePath = null; string programFilesPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); @@ -707,12 +707,11 @@ namespace System.Management.Automation return result.ToString(); } - private static bool NeedToClearCurrentProcessModulePath(string currentProcessModulePath, string personalModulePath, string programFilesModulePath, bool runningOps) + private static bool NeedToClearProcessModulePath(string currentProcessModulePath, string personalModulePath, string programFilesModulePath, bool runningOps) { #if UNIX return false; #else - Dbg.Assert(!string.IsNullOrEmpty(currentProcessModulePath), "caller makes sure it's not null or empty"); Dbg.Assert(!string.IsNullOrEmpty(personalModulePath), "caller makes sure it's not null or empty"); Dbg.Assert(!string.IsNullOrEmpty(programFilesModulePath), "caller makes sure it's not null or empty"); @@ -792,7 +791,8 @@ namespace System.Management.Automation #else bool runningOps = false; #endif - if (NeedToClearCurrentProcessModulePath(currentProcessModulePath, personalModulePath, programFilesModulePath, runningOps)) + if (!string.IsNullOrEmpty(currentProcessModulePath) && + NeedToClearProcessModulePath(currentProcessModulePath, personalModulePath, programFilesModulePath, runningOps)) { // Clear the current process module path in the following cases // - start ops on windows [machine-wide env:psmodulepath will influence]