Add the shared module path to unix (counterpart of 'Program Files\PowerShell\Modules').

Also make 'Platform.XDG_Type' and 'Platform.SelectProductNameForDirectory' unix build only, as they doesn't apply to windows.
This commit is contained in:
Dongbo Wang
2016-08-11 21:36:48 -07:00
parent 3ff19e1d80
commit 07f9fefee8
2 changed files with 16 additions and 9 deletions
@@ -203,10 +203,11 @@ namespace System.Management.Automation
#endif
}
#if UNIX
/// <summary>
/// X Desktop Group configuration type enum.
/// </summary>
public enum XDG_Type
internal enum XDG_Type
{
/// <summary> XDG_CONFIG_HOME/powershell </summary>
CONFIG,
@@ -215,7 +216,9 @@ namespace System.Management.Automation
/// <summary> XDG_DATA_HOME/powershell </summary>
DATA,
/// <summary> XDG_DATA_HOME/powershell/Modules </summary>
MODULES,
USER_MODULES,
/// <summary> /usr/local/share/powershell/Modules </summary>
SHARED_MODULES,
/// <summary> XDG_CONFIG_HOME/powershell </summary>
DEFAULT
}
@@ -223,7 +226,7 @@ namespace System.Management.Automation
/// <summary>
/// function for choosing directory location of PowerShell for profile loading
/// </summary>
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
@@ -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]